python turtle画教学楼
时间: 2023-09-01 21:07:24 浏览: 174
好的,下面是使用Python的turtle库来画一个简单的教学楼的代码:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 绘制主体部分
pen.penup()
pen.goto(-100, 0)
pen.pendown()
pen.forward(200)
pen.left(90)
pen.forward(100)
pen.left(90)
pen.forward(200)
pen.left(90)
pen.forward(100)
# 绘制顶部部分
pen.penup()
pen.goto(-90, 100)
pen.pendown()
pen.forward(60)
pen.right(90)
pen.forward(20)
pen.right(90)
pen.forward(60)
# 绘制门和窗户
pen.penup()
pen.goto(-70, 0)
pen.pendown()
pen.right(90)
pen.forward(40)
pen.left(90)
pen.forward(40)
pen.left(90)
pen.forward(40)
pen.left(90)
pen.forward(40)
pen.right(90)
pen.forward(20)
pen.right(90)
pen.forward(40)
pen.left(90)
pen.forward(20)
pen.left(90)
pen.forward(40)
# 隐藏画笔
pen.hideturtle()
# 显示画布
canvas.mainloop()
```
运行上述代码,即可在turtle画布上看到一个简单的教学楼。你也可以根据自己的需求和创意对代码进行修改和优化,进一步美化自己的作品。
阅读全文