python绘画皮卡丘
时间: 2023-11-08 13:04:55 浏览: 166
Python皮卡丘代码.rar
好的,要绘制皮卡丘,需要使用Python中的turtle库。以下是绘制皮卡丘的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('#FFE4B5')
# 画圆函数
def draw_circle(x, y, r, color):
turtle.penup()
turtle.goto(x, y - r)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(r)
turtle.end_fill()
# 画矩形函数
def draw_rect(x, y, w, h, color):
turtle.penup()
turtle.goto(x - w / 2, y - h / 2)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
for i in range(2):
turtle.forward(w)
turtle.left(90)
turtle.forward(h)
turtle.left(90)
turtle.end_fill()
# 画皮卡丘的脸
draw_circle(0, 100, 200, '#FCD116')
# 画皮卡丘的耳朵
draw_circle(-80, 220, 50, '#FCD116')
draw_circle(80, 220, 50, '#FCD116')
# 画皮卡丘的眼睛
draw_circle(-70, 140, 30, '#FFFFFF')
draw_circle(70, 140, 30, '#FFFFFF')
draw_circle(-70, 140, 10, '#000000')
draw_circle(70, 140, 10, '#000000')
# 画皮卡丘的腮红
draw_circle(-120, 60, 30, '#FF69B4')
draw_circle(120, 60, 30, '#FF69B4')
# 画皮卡丘的嘴巴
turtle.penup()
turtle.goto(-150, 20)
turtle.pendown()
turtle.pensize(10)
turtle.right(90)
turtle.circle(150, 180)
# 画皮卡丘的鼻子
draw_circle(0, 50, 20, '#000000')
# 画皮卡丘的眉毛
turtle.penup()
turtle.goto(-100, 180)
turtle.pendown()
turtle.pensize(20)
turtle.right(45)
turtle.forward(60)
turtle.penup()
turtle.goto(40, 180)
turtle.pendown()
turtle.right(90)
turtle.forward(60)
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行上述代码,即可在窗口中看到绘制出来的皮卡丘。
阅读全文