python的turtle画一个小猪佩奇
时间: 2023-11-11 18:05:53 浏览: 95
以下是一个简单的小猪佩奇的代码示例:
```python
import turtle
# 创建画布
canvas = turtle.Screen()
canvas.bgcolor("#FEECEC")
# 创建画笔
pen = turtle.Turtle()
pen.speed(0)
pen.pensize(3)
# 画小猪佩奇的头
pen.color("#F97D7D")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 画小猪佩奇的耳朵
pen.penup()
pen.goto(-50, 150)
pen.pendown()
pen.begin_fill()
pen.circle(30)
pen.end_fill()
pen.penup()
pen.goto(50, 150)
pen.pendown()
pen.begin_fill()
pen.circle(30)
pen.end_fill()
# 画小猪佩奇的眼睛
pen.penup()
pen.goto(-40, 50)
pen.pendown()
pen.color("#000000")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(40, 50)
pen.pendown()
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 画小猪佩奇的鼻子
pen.penup()
pen.goto(0, 20)
pen.pendown()
pen.color("#FF9999")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 画小猪佩奇的嘴巴
pen.penup()
pen.goto(-50, -30)
pen.pendown()
pen.color("#000000")
pen.right(45)
pen.forward(60)
pen.left(45)
pen.forward(60)
pen.left(45)
pen.forward(60)
# 画小猪佩奇的身体
pen.penup()
pen.goto(-150, -150)
pen.pendown()
pen.color("#F97D7D")
pen.begin_fill()
pen.forward(300)
pen.right(90)
pen.circle(50, 180)
pen.right(90)
pen.forward(300)
pen.end_fill()
# 画小猪佩奇的手
pen.penup()
pen.goto(-150, -150)
pen.pendown()
pen.color("#FF9999")
pen.begin_fill()
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.end_fill()
pen.penup()
pen.goto(150, -150)
pen.pendown()
pen.begin_fill()
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.end_fill()
# 画小猪佩奇的脚
pen.penup()
pen.goto(-100, -250)
pen.pendown()
pen.color("#FF9999")
pen.begin_fill()
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.right(45)
pen.forward(50)
pen.end_fill()
pen.penup()
pen.goto(100, -250)
pen.pendown()
pen.begin_fill()
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 结束画布
canvas.exitonclick()
```
运行代码后,会弹出一个画布,上面画着一个小猪佩奇的图形。可以根据需要修改颜色、大小等参数,让小猪佩奇更加可爱。
阅读全文