Python画一个小猪佩奇
时间: 2023-05-11 19:06:25 浏览: 195
可以使用Python的turtle库来画一个小猪佩奇,以下是代码示例:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#F0EFEF")
# 画小猪佩奇的头
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.fillcolor("#FDB9B9")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画小猪佩奇的耳朵
turtle.penup()
turtle.goto(-150, 200)
turtle.pendown()
turtle.fillcolor("#FDB9B9")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(-50, 200)
turtle.pendown()
turtle.fillcolor("#FDB9B9")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画小猪佩奇的眼睛
turtle.penup()
turtle.goto(-70, 130)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 130)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, 140)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 140)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画小猪佩奇的鼻子
turtle.penup()
turtle.goto(-50, 100)
turtle.pendown()
turtle.fillcolor("#FFAFAF")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画小猪佩奇的嘴巴
turtle.penup()
turtle.goto(-70, 70)
turtle.pendown()
turtle.pensize(10)
turtle.right(45)
turtle.circle(50, 90)
# 画小猪佩奇的身体
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
turtle.fillcolor("#FDB9B9")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画小猪佩奇的手
turtle.penup()
turtle.goto(-150, -50)
turtle.pendown()
turtle.fillcolor("#FDB9B9")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
turtle.fillcolor("#FDB9B9")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画小猪佩奇的脚
turtle.penup()
turtle.goto(-70, -150)
turtle.pendown()
turtle.fillcolor("#FFAFAF")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(30, -150)
turtle.pendown()
turtle.fillcolor("#FFAFAF")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,即可在窗口中看到一个可爱的小猪佩奇。
阅读全文