用turtle画个佩琪
时间: 2024-06-09 15:07:21 浏览: 149
Python使用turtle库绘制小猪佩奇(实例代码)
5星 · 资源好评率100%
好的,下面是使用Python的turtle库绘制佩琪的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('#FFC0CB')
# 绘制佩琪的头
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.circle(120)
turtle.end_fill()
# 绘制佩琪的眼睛
turtle.penup()
turtle.goto(-40, 160)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 160)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制佩琪的鼻子
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.fillcolor('#FFC0CB')
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
# 绘制佩琪的嘴巴
turtle.penup()
turtle.goto(-60, 20)
turtle.pendown()
turtle.pensize(8)
turtle.right(60)
turtle.circle(80, 120)
# 绘制佩琪的身体
turtle.penup()
turtle.goto(-150, -80)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.forward(300)
turtle.left(90)
turtle.circle(150, 180)
turtle.left(90)
turtle.forward(300)
turtle.end_fill()
# 绘制佩琪的手臂
turtle.penup()
turtle.goto(-150, -80)
turtle.pendown()
turtle.fillcolor('#FFC0CB')
turtle.begin_fill()
turtle.right(45)
turtle.forward(100)
turtle.right(45)
turtle.forward(80)
turtle.right(90)
turtle.forward(80)
turtle.right(45)
turtle.forward(100)
turtle.right(135)
turtle.forward(100)
turtle.right(45)
turtle.forward(80)
turtle.right(90)
turtle.forward(80)
turtle.right(45)
turtle.forward(100)
turtle.end_fill()
# 绘制佩琪的脚
turtle.penup()
turtle.goto(-70, -300)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.right(90)
turtle.forward(80)
turtle.right(90)
turtle.forward(150)
turtle.right(90)
turtle.forward(80)
turtle.end_fill()
turtle.penup()
turtle.goto(70, -300)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.right(90)
turtle.forward(80)
turtle.right(90)
turtle.forward(150)
turtle.right(90)
turtle.forward(80)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘制结果
turtle.done()
```
这是绘制出的佩琪的图片:
![佩琪](https://i.imgur.com/zzSjKBA.png)
阅读全文