使用python海龟绘图画一盘粽子
时间: 2023-07-15 08:14:08 浏览: 132
好的,以下是绘制粽子的Python海龟绘图代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#ffcc66")
# 画出粽叶
turtle.penup()
turtle.goto(-200, 200)
turtle.pendown()
turtle.fillcolor("#006600")
turtle.begin_fill()
for i in range(3):
turtle.forward(400)
turtle.right(120)
turtle.end_fill()
# 画出粽子绳
turtle.penup()
turtle.goto(0, 200)
turtle.pendown()
turtle.pensize(10)
turtle.pencolor("#996600")
turtle.circle(50)
# 画出粽子身体
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.fillcolor("#996633")
turtle.begin_fill()
turtle.circle(150)
turtle.end_fill()
# 画出粽子口袋
turtle.penup()
turtle.goto(0, -60)
turtle.pendown()
turtle.fillcolor("#ffcc66")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画出粽子口袋上的花纹
turtle.penup()
turtle.goto(0, -10)
turtle.pendown()
turtle.pencolor("#ff99cc")
turtle.pensize(5)
for i in range(8):
turtle.circle(80, 45)
# 完成绘制
turtle.done()
```
运行该代码,就可以看到绘制出来的粽子了。效果如下:
![粽子绘图](https://cdn.luogu.com.cn/upload/image_hosting/fn7qtf3z.png)
阅读全文