python画皮卡丘代码
时间: 2023-10-07 19:11:25 浏览: 187
以下是使用Python Turtle库画皮卡丘的代码:
```python
import turtle
# 画圆函数
def circle(x, y, r):
turtle.penup()
turtle.goto(x, y - r)
turtle.pendown()
turtle.circle(r)
# 画矩形函数
def rect(x, y, width, height):
turtle.penup()
turtle.goto(x - width/2, y - height/2)
turtle.pendown()
turtle.forward(width)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.forward(width)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
# 画皮卡丘
turtle.speed(10)
turtle.bgcolor("#F5F5F5")
turtle.fillcolor("#F9D71C")
turtle.begin_fill()
circle(0, 100, 80) # 脸
turtle.end_fill()
turtle.fillcolor("#000000")
turtle.begin_fill()
circle(-25, 140, 10) # 左眼
turtle.end_fill()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
circle(-25, 145, 5) # 左眼珠
turtle.end_fill()
turtle.fillcolor("#000000")
turtle.begin_fill()
circle(25, 140, 10) # 右眼
turtle.end_fill()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
circle(25, 145, 5) # 右眼珠
turtle.end_fill()
turtle.penup()
turtle.goto(0, 60)
turtle.pendown()
turtle.width(8)
turtle.right(90)
turtle.forward(30)
turtle.penup()
turtle.goto(-25, 30)
turtle.pendown()
turtle.fillcolor("#F9D71C")
turtle.begin_fill()
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(20)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.width(1)
turtle.fillcolor("#FF0000")
turtle.begin_fill()
circle(0, 10, 30) # 嘴
turtle.end_fill()
turtle.penup()
turtle.goto(-60, -20)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
rect(-60, -20, 120, 20) # 身体
turtle.end_fill()
turtle.penup()
turtle.goto(-60, -40)
turtle.pendown()
turtle.fillcolor("#F9D71C")
turtle.begin_fill()
rect(-60, -40, 120, 20) # 腹部
turtle.end_fill()
turtle.penup()
turtle.goto(-70, -70)
turtle.pendown()
turtle.fillcolor("#F9D71C")
turtle.begin_fill()
rect(-70, -70, 140, 30) # 尾巴
turtle.end_fill()
turtle.penup()
turtle.goto(-85, -70)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
rect(-85, -70, 30, 30) # 尾巴末端
turtle.end_fill()
turtle.penup()
turtle.goto(85, -70)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
rect(55, -70, 30, 30) # 尾巴末端
turtle.end_fill()
turtle.hideturtle()
turtle.done()
```
运行以上代码,就可以看到画出的皮卡丘了!
阅读全文