python画皮卡丘并上色代码
时间: 2024-01-10 07:04:29 浏览: 168
以下是用Python画皮卡丘并上色的代码:
```
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('#FEE12B')
# 画圆函数
def draw_circle(x, y, r, color):
turtle.penup()
turtle.goto(x, y)
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, y)
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, 0, 200, '#FEE12B')
# 画皮卡丘的耳朵
draw_circle(-150, 150, 50, '#FEE12B')
draw_circle(150, 150, 50, '#FEE12B')
# 画皮卡丘的眼睛
draw_circle(-70, 50, 30, '#FFFFFF')
draw_circle(70, 50, 30, '#FFFFFF')
draw_circle(-70, 50, 10, '#000000')
draw_circle(70, 50, 10, '#000000')
# 画皮卡丘的鼻子
draw_circle(0, 0, 20, '#000000')
# 画皮卡丘的嘴巴
draw_rect(-70, -80, 140, 20, '#000000')
draw_rect(-50, -100, 100, 20, '#FEE12B')
# 画皮卡丘的腮红
draw_circle(-120, -30, 30, '#FF5B5B')
draw_circle(120, -30, 30, '#FF5B5B')
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
阅读全文