用python画一幅故宫的画
时间: 2023-06-30 08:09:33 浏览: 238
好的!下面是一个简单的Python代码,可以画出故宫的轮廓:
```python
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔颜色和大小
turtle.pensize(3)
turtle.color("black")
# 绘制故宫南门
turtle.penup()
turtle.goto(-300, -200)
turtle.pendown()
turtle.forward(200)
turtle.left(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(300)
turtle.left(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(200)
# 绘制故宫正门
turtle.penup()
turtle.goto(-200, -100)
turtle.pendown()
turtle.forward(100)
turtle.right(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(200)
# 绘制故宫角楼
turtle.penup()
turtle.goto(-300, 100)
turtle.pendown()
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
# 绘制故宫大殿
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
turtle.forward(300)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(300)
turtle.left(90)
turtle.forward(200)
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
运行代码后,会弹出一个窗口,显示出绘制的故宫轮廓。如果需要更加精细的绘图,可以对代码进行修改和优化。
阅读全文