用python画一个小猪佩奇
时间: 2023-09-13 11:13:00 浏览: 165
python绘制小猪佩奇py代码_python代码_python_小猪佩奇python_transportation9lf_
好的,下面是用Python的turtle库画小猪佩奇的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('#FBD2D7')
# 画小猪佩奇的头
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画小猪佩奇的耳朵
turtle.penup()
turtle.goto(-160, 180)
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.right(45)
turtle.circle(70, -90)
turtle.right(180)
turtle.circle(70, -90)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 180)
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.right(180)
turtle.circle(70, -90)
turtle.right(45)
turtle.circle(70, -90)
turtle.end_fill()
# 画小猪佩奇的眼睛
turtle.penup()
turtle.goto(-50, 180)
turtle.pendown()
turtle.fillcolor('white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 180)
turtle.pendown()
turtle.fillcolor('white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 200)
turtle.pendown()
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 200)
turtle.pendown()
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画小猪佩奇的鼻子
turtle.penup()
turtle.goto(, 120)
turtle.pendown()
turtle.fillcolor('#FFA07A')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画小猪佩奇的嘴巴
turtle.penup()
turtle.goto(-60, 80)
turtle.pendown()
turtle.pensize(10)
turtle.right(45)
turtle.forward(80)
turtle.right(180)
turtle.circle(40, -90)
# 画小猪佩奇的身体
turtle.penup()
turtle.goto(-100, -100)
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.right(135)
turtle.forward(200)
turtle.right(90)
turtle.circle(100, -180)
turtle.right(90)
turtle.forward(200)
turtle.end_fill()
# 画小猪佩奇的手
turtle.penup()
turtle.goto(-200, )
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.right(180)
turtle.circle(50, -90)
turtle.right(180)
turtle.circle(50, -90)
turtle.end_fill()
turtle.penup()
turtle.goto(100, )
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.right(180)
turtle.circle(50, -90)
turtle.right(180)
turtle.circle(50, -90)
turtle.end_fill()
# 画小猪佩奇的脚
turtle.penup()
turtle.goto(-80, -200)
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.right(180)
turtle.circle(50, -90)
turtle.right(180)
turtle.circle(50, -90)
turtle.end_fill()
turtle.penup()
turtle.goto(20, -200)
turtle.pendown()
turtle.fillcolor('#F5A9BC')
turtle.begin_fill()
turtle.right(180)
turtle.circle(50, -90)
turtle.right(180)
turtle.circle(50, -90)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行代码后,会弹出一个窗口,里面画着小猪佩奇的图案。希望能对你有所帮助!
阅读全文