python粽子代码
时间: 2023-07-03 09:24:22 浏览: 107
以下是制作Python粽子的代码示例:
```python
# 导入绘图库
import turtle
# 设置绘图窗口
win = turtle.Screen()
win.setup(width=600, height=600)
# 绘制粽叶
leaf = turtle.Turtle()
leaf.penup()
leaf.goto(-150, 150)
leaf.pendown()
leaf.fillcolor('#3d9970')
leaf.begin_fill()
leaf.right(45)
leaf.forward(100)
leaf.right(135)
leaf.forward(200)
leaf.right(135)
leaf.forward(100)
leaf.right(135)
leaf.forward(200)
leaf.right(135)
leaf.end_fill()
# 绘制粽子身体
body = turtle.Turtle()
body.penup()
body.goto(-100, 0)
body.pendown()
body.fillcolor('#e74c3c')
body.begin_fill()
body.circle(100)
body.end_fill()
# 绘制粽绳
rope = turtle.Turtle()
rope.penup()
rope.goto(-25, 150)
rope.pendown()
rope.pensize(5)
rope.pencolor('#333')
rope.right(30)
rope.forward(50)
rope.right(120)
rope.forward(50)
rope.right(120)
rope.forward(50)
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
运行代码后,将会绘制出一个粽子的图形,其中包含粽叶、粽子身体和粽绳等元素。
阅读全文