Python故宫代码
时间: 2023-11-19 10:50:36 浏览: 143
以下是使用Python实现的故宫代码示例:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔大小和颜色
turtle.pensize(5)
turtle.pencolor('black')
# 绘制故宫外墙
turtle.penup()
turtle.goto(-300, -200)
turtle.pendown()
turtle.fillcolor('#FFD700')
turtle.begin_fill()
turtle.forward(600)
turtle.left(90)
turtle.forward(400)
turtle.left(90)
turtle.forward(600)
turtle.left(90)
turtle.forward(400)
turtle.end_fill()
# 绘制故宫内院
turtle.penup()
turtle.goto(-200, -100)
turtle.pendown()
turtle.fillcolor('#FF69B4')
turtle.begin_fill()
turtle.forward(400)
turtle.left(90)
turtle.forward(300)
turtle.left(90)
turtle.forward(400)
turtle.left(90)
turtle.forward(300)
turtle.end_fill()
# 绘制故宫门楼
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.fillcolor('#FFD700')
turtle.begin_fill()
turtle.forward(200)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(200)
turtle.end_fill()
# 绘制故宫门楼顶部
turtle.penup()
turtle.goto(-220, 200)
turtle.pendown()
turtle.fillcolor('#FF69B4')
turtle.begin_fill()
turtle.forward(240)
turtle.left(120)
turtle.forward(240)
turtle.left(120)
turtle.forward(240)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
阅读全文