python代码画皮卡丘
时间: 2023-10-08 13:04:04 浏览: 179
以下是使用Python Turtle模块画皮卡丘的示例代码:
```python
import turtle
# 画圆函数
def draw_circle(x, y, r):
turtle.penup()
turtle.goto(x, y-r)
turtle.pendown()
turtle.circle(r)
# 画矩形函数
def draw_rect(x, y, w, h):
turtle.penup()
turtle.goto(x-w/2, y-h/2)
turtle.pendown()
turtle.forward(w)
turtle.left(90)
turtle.forward(h)
turtle.left(90)
turtle.forward(w)
turtle.left(90)
turtle.forward(h)
# 画皮卡丘
turtle.speed(10)
turtle.bgcolor("#FED14C")
turtle.color("#000000")
draw_circle(0, 100, 100) # 头
turtle.color("#FFFFFF")
draw_circle(-30, 120, 20) # 左眼白
draw_circle(30, 120, 20) # 右眼白
turtle.color("#000000")
draw_circle(-30, 120, 10) # 左眼黑
draw_circle(30, 120, 10) # 右眼黑
turtle.color("#FC6D26")
draw_rect(0, 70, 80, 20) # 鼻子
turtle.color("#000000")
draw_rect(-50, 30, 20, 50) # 左耳
draw_rect(50, 30, 20, 50) # 右耳
turtle.color("#FC6D26")
draw_rect(0, 0, 80, 60) # 嘴巴
turtle.done()
```
运行以上代码,将会在窗口中画出一个皮卡丘。
阅读全文