python的turtle画一个小猪佩奇
时间: 2023-11-11 11:06:05 浏览: 43
以下是使用Python的turtle库绘制小猪佩奇的代码:
```
import turtle
# 设置小猪佩奇的画笔颜色和背景颜色
turtle.pencolor('#000000')
turtle.bgcolor('#F0E8E8')
# 绘制小猪佩奇的头部
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.circle(100)
# 绘制小猪佩奇的耳朵
turtle.penup()
turtle.goto(-75, 180)
turtle.pendown()
turtle.setheading(-60)
turtle.circle(80, 120)
turtle.setheading(60)
turtle.circle(-80, 120)
# 绘制小猪佩奇的眼睛
turtle.penup()
turtle.goto(-40, 150)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-20, 160)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 150)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 160)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
# 绘制小猪佩奇的鼻子
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.setheading(270)
turtle.fillcolor('#FF9C9C')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 80)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(12)
turtle.end_fill()
# 绘制小猪佩奇的脸颊
turtle.penup()
turtle.goto(-70, 40)
turtle.pendown()
turtle.setheading(-30)
turtle.fillcolor('#FF9C9C')
turtle.begin_fill()
turtle.circle(70, 120)
turtle.setheading(150)
turtle.circle(-70, 120)
turtle.end_fill()
# 绘制小猪佩奇的嘴巴
turtle.penup()
turtle.goto(-60, 10)
turtle.pendown()
turtle.setheading(-30)
turtle.fillcolor('#F0E8E8')
turtle.begin_fill()
turtle.circle(60, 120)
turtle.setheading(150)
turtle.circle(-60, 120)
turtle.end_fill()
# 绘制小猪佩奇的身体
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.fillcolor('#FF9C9C')
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 绘制小猪佩奇的手臂
turtle.penup()
turtle.goto(-120, -100)
turtle.pendown()
turtle.fillcolor('#FF9C9C')
turtle.begin_fill()
turtle.setheading(-110)
turtle.circle(120, 60)
turtle.setheading(30)
turtle.circle(-20, 180)
turtle.setheading(110)
turtle.circle(-120, 60)
turtle.setheading(180)
turtle.circle(20, 180)
turtle.end_fill()
# 绘制小猪佩奇的脚
turtle.penup()
turtle.goto(-70, -180)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.setheading(-90)
turtle.circle(70, 180)
turtle.setheading(0)
turtle.circle(20, 180)
turtle.end_fill()
turtle.penup()
turtle.goto(70, -180)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.setheading(-90)
turtle.circle(-70, 180)
turtle.setheading(180)
turtle.circle(-20, 180)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码后,会弹出一个窗口,显示绘制的小猪佩奇。效果如下:
![小猪佩奇](https://i.imgur.com/fF3q1Tj.png)
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)