python画一个小猪佩奇
时间: 2023-07-07 21:45:20 浏览: 105
使用python画个小猪佩奇的示例代码
可以使用Python的turtle库来画小猪佩奇。以下是一个简单的示例代码:
```python
import turtle
# 画猪头
def draw_head():
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画眼睛
def draw_eyes():
turtle.penup()
turtle.goto(-35, 130)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(35, 130)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 画鼻子
def draw_nose():
turtle.penup()
turtle.goto(0, 90)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画嘴巴
def draw_mouth():
turtle.penup()
turtle.goto(-60, 60)
turtle.pendown()
turtle.right(45)
turtle.circle(80, 90)
# 画身体和四肢
def draw_body_and_limbs():
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
turtle.begin_fill()
turtle.setheading(-45)
turtle.forward(200)
turtle.setheading(135)
turtle.forward(100)
turtle.setheading(45)
turtle.forward(200)
turtle.setheading(-135)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
turtle.setheading(-135)
turtle.forward(80)
turtle.setheading(-45)
turtle.begin_fill()
turtle.forward(20)
turtle.right(90)
turtle.circle(30, 180)
turtle.right(90)
turtle.forward(20)
turtle.end_fill()
turtle.penup()
turtle.goto(100, 0)
turtle.pendown()
turtle.setheading(45)
turtle.forward(80)
turtle.setheading(135)
turtle.begin_fill()
turtle.forward(20)
turtle.left(90)
turtle.circle(-30, 180)
turtle.left(90)
turtle.forward(20)
turtle.end_fill()
# 设置画布和画笔
turtle.setup(500, 500)
turtle.color('pink')
turtle.pensize(5)
turtle.speed(0)
# 画小猪佩奇
draw_head()
draw_eyes()
draw_nose()
draw_mouth()
draw_body_and_limbs()
turtle.done()
```
运行上述代码后,会弹出一个画布,上面会画出一个可爱的小猪佩奇。
阅读全文