用turtle库和random库画一个饺子
时间: 2024-05-23 11:12:37 浏览: 97
好的,下面是用turtle库和random库画一个饺子的代码:
```python
import turtle
import random
# 设置画笔
t = turtle.Turtle()
t.speed(0)
t.penup()
t.goto(-100, 0)
t.pendown()
# 饺子皮
t.color("orange", "white")
t.begin_fill()
t.circle(50)
t.end_fill()
# 饺子馅
t.penup()
t.goto(-70, 0)
t.pendown()
t.color("brown", "pink")
t.begin_fill()
for i in range(8):
t.forward(30)
t.right(45)
t.forward(30)
t.left(135)
t.end_fill()
# 饺子的褶皱
for i in range(10):
t.penup()
x = random.randint(-40, 40)
y = random.randint(-30, 30)
t.goto(x, y)
t.pendown()
t.color("black")
t.right(random.randint(0, 360))
t.circle(random.randint(5, 15), random.randint(30, 120))
# 隐藏画笔
t.hideturtle()
# 显示结果
turtle.done()
```
运行结果如下图所示:
![饺子](https://img-blog.csdnimg.cn/20210923151725735.png)
阅读全文