turtle绘制摩天轮
时间: 2023-11-13 08:50:57 浏览: 156
turtle作图作品
以下是使用Python的turtle模块绘制摩天轮的示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#F0F0F0")
# 定义绘制圆弧函数
def draw_arc(radius, angle):
turtle.circle(radius, angle)
# 绘制摩天轮的底部
turtle.penup()
turtle.goto(-200, -200)
turtle.pendown()
turtle.color("#C0C0C0")
turtle.begin_fill()
for i in range(4):
turtle.forward(400)
turtle.left(90)
turtle.end_fill()
# 绘制摩天轮的支架
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(270)
turtle.color("#808080")
turtle.pensize(20)
turtle.forward(200)
draw_arc(100, 180)
turtle.forward(200)
# 绘制摩天轮的车厢
turtle.penup()
turtle.goto(-150, 50)
turtle.pendown()
turtle.color("#FF69B4")
turtle.pensize(2)
turtle.begin_fill()
for i in range(3):
turtle.forward(100)
turtle.left(120)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, 50)
turtle.pendown()
turtle.begin_fill()
for i in range(4):
turtle.forward(50)
turtle.left(90)
turtle.end_fill()
# 绘制摩天轮的轮盘
turtle.penup()
turtle.goto(0, 200)
turtle.pendown()
turtle.color("#000080")
turtle.pensize(2)
turtle.begin_fill()
draw_arc(200, 360)
turtle.end_fill()
# 绘制摩天轮的座椅
turtle.penup()
turtle.goto(0, 400)
turtle.pendown()
turtle.color("#FFFFFF")
turtle.pensize(2)
for i in range(8):
turtle.penup()
turtle.goto(0, 200)
turtle.pendown()
turtle.setheading(i * 45)
turtle.forward(150)
turtle.begin_fill()
draw_arc(50, 180)
turtle.end_fill()
turtle.hideturtle()
turtle.done()
```
运行上述代码,即可在窗口中看到绘制出的摩天轮。
阅读全文