请用python的turtle库帮我绘制一只可爱的小羊,并将源代码给我
时间: 2024-05-03 15:20:45 浏览: 85
Python利用turtle库绘制彩虹代码示例
5星 · 资源好评率100%
好的,我可以帮你绘制一只小羊。以下是Python代码:
```python
import turtle
# 画圆
def draw_circle(radius, color):
turtle.penup()
turtle.goto(0, -radius)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
turtle.circle(radius)
turtle.end_fill()
# 画长方形
def draw_rectangle(width, height, color):
turtle.penup()
turtle.goto(-width/2, -height/2)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
for i in range(2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()
# 画小羊
def draw_sheep():
turtle.speed(0)
draw_circle(80, 'white') # 身体
draw_circle(15, 'black') # 左眼
turtle.goto(0, 0)
draw_circle(16, 'white') # 右眼
turtle.goto(-25, 15)
draw_rectangle(50, 10, 'black') # 嘴巴
# 主程序
draw_sheep()
turtle.done()
```
运行此代码,将会显示一个可爱的小羊的图像,并生成源代码。
阅读全文