python turtle画学校大楼
时间: 2023-09-05 11:10:06 浏览: 317
好的,以下是一个简单的 Python Turtle 代码,用于画一个学校大楼的图像:
```python
import turtle
# 绘制大楼主体
def draw_building():
turtle.pensize(5)
turtle.color("grey")
turtle.begin_fill()
turtle.forward(200)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(400)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(200)
turtle.end_fill()
# 绘制窗户
def draw_windows():
turtle.pensize(2)
turtle.color("white")
for i in range(4):
turtle.penup()
turtle.goto(-150 + i * 100, 50)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 绘制门
def draw_door():
turtle.pensize(3)
turtle.color("brown")
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.begin_fill()
turtle.forward(80)
turtle.left(90)
turtle.forward(150)
turtle.left(90)
turtle.forward(80)
turtle.left(90)
turtle.forward(150)
turtle.end_fill()
# 绘制门把手
def draw_door_handle():
turtle.penup()
turtle.goto(0, -30)
turtle.pendown()
turtle.color("yellow")
turtle.dot(20)
# 绘制屋顶
def draw_roof():
turtle.pensize(5)
turtle.color("black")
turtle.penup()
turtle.goto(-200, 200)
turtle.pendown()
turtle.begin_fill()
turtle.goto(0, 300)
turtle.goto(200, 200)
turtle.end_fill()
# 主程序
turtle.speed(1)
draw_building()
draw_windows()
draw_door()
draw_door_handle()
draw_roof()
turtle.done()
```
运行上述代码,你将得到一个学校大楼的图像。你可以根据自己的需求进行修改,例如更改颜色、调整大小等等。
阅读全文