python turtle房子代码
时间: 2023-07-22 11:09:17 浏览: 442
简单python-画房子
5星 · 资源好评率100%
以下是Python Turtle画房子的代码示例:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 400)
turtle.bgcolor('lightblue')
# 画房子的墙
turtle.penup()
turtle.goto(-200, -100)
turtle.pendown()
turtle.color('white')
turtle.begin_fill()
for i in range(2):
turtle.forward(400)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.end_fill()
# 画房子的屋顶
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.color('brown')
turtle.begin_fill()
turtle.goto(, 200)
turtle.goto(200, 100)
turtle.goto(-200, 100)
turtle.end_fill()
# 画房子的门
turtle.penup()
turtle.goto(-50, -100)
turtle.pendown()
turtle.color('brown')
turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(150)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(150)
turtle.end_fill()
# 画房子的窗户
turtle.penup()
turtle.goto(-150, 50)
turtle.pendown()
turtle.color('brown')
turtle.begin_fill()
for i in range(4):
turtle.forward(50)
turtle.left(90)
turtle.end_fill()
turtle.penup()
turtle.goto(100, 50)
turtle.pendown()
turtle.color('brown')
turtle.begin_fill()
for i in range(4):
turtle.forward(50)
turtle.left(90)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,即可在Turtle画布上看到一个简单的房子。
阅读全文