python用turtle绘制一个小屋
时间: 2023-07-04 14:12:56 浏览: 133
python用turtle画画
好的,以下是用Python的turtle库绘制小屋的代码:
```python
import turtle
# 绘制房屋的墙壁
turtle.penup()
turtle.goto(-200, -100)
turtle.pendown()
turtle.forward(200)
turtle.left(90)
turtle.forward(150)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(150)
# 绘制房屋的屋顶
turtle.penup()
turtle.goto(-200, 50)
turtle.pendown()
turtle.right(45)
turtle.forward(141)
turtle.right(90)
turtle.forward(141)
# 绘制房屋的门
turtle.penup()
turtle.goto(-150, -100)
turtle.pendown()
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(40)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(40)
# 绘制房屋的窗户
turtle.penup()
turtle.goto(-80, 0)
turtle.pendown()
turtle.forward(40)
turtle.left(90)
turtle.forward(40)
turtle.left(90)
turtle.forward(40)
turtle.left(90)
turtle.forward(40)
# 绘制房屋的烟囱
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.begin_fill()
turtle.forward(30)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(30)
turtle.end_fill()
# 完成绘制
turtle.done()
```
运行上述代码,你可以看到绘制了一个简单的小屋。
阅读全文