python turtle画学校大楼
时间: 2023-09-05 09:10:06 浏览: 162
好的,下面是一个简单的 Python 代码示例,用于使用 Turtle 模块绘制学校大楼:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('lightblue')
# 绘制大楼主体
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color('white')
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.end_fill()
# 绘制屋顶和窗户
turtle.penup()
turtle.goto(-200, 200)
turtle.pendown()
turtle.begin_fill()
turtle.color('darkblue')
turtle.left(45)
turtle.forward(283)
turtle.right(90)
turtle.forward(283)
turtle.left(135)
turtle.forward(200)
turtle.end_fill()
turtle.penup()
turtle.goto(-150, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
turtle.circle(30)
turtle.end_fill()
# 绘制门和树
turtle.penup()
turtle.goto(-60, -200)
turtle.pendown()
turtle.begin_fill()
turtle.color('brown')
turtle.forward(120)
turtle.right(90)
turtle.forward(150)
turtle.right(90)
turtle.forward(120)
turtle.right(90)
turtle.forward(150)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, -200)
turtle.pendown()
turtle.begin_fill()
turtle.color('lightgray')
turtle.forward(60)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(60)
turtle.right(90)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(200, -200)
turtle.pendown()
turtle.begin_fill()
turtle.color('brown')
turtle.forward(50)
turtle.right(120)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(120)
turtle.forward(50)
turtle.end_fill()
turtle.penup()
turtle.goto(180, -20)
turtle.pendown()
turtle.begin_fill()
turtle.color('green')
turtle.circle(50)
turtle.end_fill()
# 隐藏海龟
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
上面的代码将绘制一个简单的学校大楼,包括主体、屋顶、窗户、门和树。您可以根据需要进行修改和调整,以获得更逼真的效果。
阅读全文