使用turtle库绘制小鸡
时间: 2023-10-23 20:14:30 浏览: 201
如何使用python的自带turtle库.docx
好的,下面是使用turtle库绘制小鸡的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(500, 500)
turtle.bgcolor("lightblue")
# 设置画笔颜色和宽度
turtle.pencolor("orange")
turtle.pensize(5)
# 绘制小鸡头
turtle.circle(50)
# 绘制小鸡身体
turtle.penup()
turtle.goto(0, -70)
turtle.pendown()
turtle.begin_fill()
turtle.circle(70)
turtle.end_fill()
# 绘制小鸡腿
turtle.penup()
turtle.goto(-20, -140)
turtle.pendown()
turtle.setheading(45)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.penup()
turtle.goto(20, -140)
turtle.pendown()
turtle.setheading(135)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
# 绘制小鸡嘴巴
turtle.penup()
turtle.goto(-25, 35)
turtle.pendown()
turtle.setheading(-60)
turtle.circle(30, 120)
# 绘制小鸡眼睛
turtle.penup()
turtle.goto(-15, 80)
turtle.pendown()
turtle.dot(25)
turtle.penup()
turtle.goto(-20, 90)
turtle.pendown()
turtle.dot(10)
turtle.penup()
turtle.goto(15, 80)
turtle.pendown()
turtle.dot(25)
turtle.penup()
turtle.goto(20, 90)
turtle.pendown()
turtle.dot(10)
turtle.done()
```
运行以上代码,会弹出一个绘制小鸡的窗口。效果如下图所示:
![小鸡](https://img-blog.csdn.net/20180819214023791?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3h4eHg5NjM4MjU3Nw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/70)
阅读全文