用python turtle画一个小猪佩奇
时间: 2023-04-10 08:00:24 浏览: 173
Python使用turtle库绘制小猪佩奇(实例代码)
5星 · 资源好评率100%
好的,我可以回答这个问题。以下是使用 Python turtle 库绘制小猪佩奇的代码示例:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#F0E0D0")
# 绘制小猪佩奇的头部
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.fillcolor("#F4CCCC")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 绘制小猪佩奇的眼睛
turtle.penup()
turtle.goto(-60, 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(10)
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(40, 160)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制小猪佩奇的鼻子
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.fillcolor("#FFC0CB")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 绘制小猪佩奇的嘴巴
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.pensize(10)
turtle.right(45)
turtle.circle(70, 90)
# 绘制小猪佩奇的身体
turtle.penup()
turtle.goto(-150, -50)
turtle.pendown()
turtle.fillcolor("#F4CCCC")
turtle.begin_fill()
turtle.forward(300)
turtle.right(90)
turtle.circle(50, 180)
turtle.right(90)
turtle.forward(300)
turtle.end_fill()
# 绘制小猪佩奇的手臂
turtle.penup()
turtle.goto(-150, 0)
turtle.pendown()
turtle.fillcolor("#F4CCCC")
turtle.begin_fill()
turtle.right(45)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(135)
turtle.forward(70)
turtle.end_fill()
turtle.penup()
turtle.goto(150, 0)
turtle.pendown()
turtle.fillcolor("#F4CCCC")
turtle.begin_fill()
turtle.right(135)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(45)
turtle.forward(70)
turtle.end_fill()
# 绘制小猪佩奇的脚
turtle.penup()
turtle.goto(-100, -150)
turtle.pendown()
turtle.fillcolor("#FFC0CB")
turtle.begin_fill()
turtle.right(45)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(135)
turtle.forward(70)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -150)
turtle.pendown()
turtle.fillcolor("#FFC0CB")
turtle.begin_fill()
turtle.right(135)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(45)
turtle.forward(70)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示绘制结果
turtle.done()
```
运行上述代码,即可在 Turtle 图形窗口中看到绘制的小猪佩奇。
阅读全文