python用turtle画沸羊羊
时间: 2023-06-30 19:09:40 浏览: 352
以下是使用Python的turtle库画沸羊羊的代码:
```python
import turtle
# 设置画笔初始位置和朝向
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.setheading(-60)
# 画出羊的头部和身体
turtle.begin_fill()
turtle.circle(50, steps=3)
turtle.color('yellow')
turtle.end_fill()
turtle.begin_fill()
turtle.circle(-50, steps=3)
turtle.color('white')
turtle.end_fill()
# 画出羊的脚
turtle.penup()
turtle.goto(-60, 0)
turtle.pendown()
turtle.setheading(-90)
turtle.color('black')
turtle.begin_fill()
turtle.forward(30)
turtle.right(90)
turtle.forward(10)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(10)
turtle.end_fill()
turtle.penup()
turtle.goto(10, 0)
turtle.pendown()
turtle.setheading(-90)
turtle.color('black')
turtle.begin_fill()
turtle.forward(30)
turtle.right(90)
turtle.forward(10)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(10)
turtle.end_fill()
# 画出羊的耳朵和眼睛
turtle.penup()
turtle.goto(-90, 120)
turtle.pendown()
turtle.setheading(60)
turtle.color('white')
turtle.begin_fill()
turtle.circle(-20, steps=3)
turtle.end_fill()
turtle.penup()
turtle.goto(-85, 130)
turtle.pendown()
turtle.setheading(0)
turtle.color('black')
turtle.begin_fill()
turtle.circle(-5)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 120)
turtle.pendown()
turtle.setheading(120)
turtle.color('white')
turtle.begin_fill()
turtle.circle(-20, steps=3)
turtle.end_fill()
turtle.penup()
turtle.goto(-55, 130)
turtle.pendown()
turtle.setheading(0)
turtle.color('black')
turtle.begin_fill()
turtle.circle(-5)
turtle.end_fill()
# 完成画图
turtle.hideturtle()
turtle.done()
```
运行代码后,就可以在turtle窗口里看到画出来的沸羊羊了。
阅读全文