用python绘制皮卡丘代码
时间: 2023-10-29 13:15:00 浏览: 87
使用Python的turtle模块绘制皮卡丘图案
以下是用 Python 绘制皮卡丘的代码:
```python
import turtle
# 设置窗口大小
turtle.setup(width=800, height=600)
# 绘制圆形
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_semicircle(x, y, r, color, angle):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.setheading(270)
turtle.circle(r, angle)
turtle.goto(x, y)
turtle.end_fill()
# 绘制眼睛
def draw_eye(x, y, r):
draw_circle(x, y, r, 'white')
draw_circle(x + r/3, y + r/2, r/4, 'black')
draw_circle(x + r/3, y + r/2, r/8, 'white')
# 绘制嘴巴
def draw_mouth(x, y, r):
draw_semicircle(x, y, r, 'red', 180)
# 绘制脸部
def draw_face():
draw_circle(0, 0, 200, 'yellow')
draw_circle(-70, 100, 50, 'white')
draw_circle(70, 100, 50, 'white')
draw_circle(-60, 110, 20, 'black')
draw_circle(60, 110, 20, 'black')
draw_semicircle(0, -50, 120, 'red', 180)
# 绘制皮卡丘
def draw_pikachu():
draw_face()
draw_eye(-80, 150, 30)
draw_eye(80, 150, 30)
draw_mouth(0, 0, 150)
# 调用绘制函数
draw_pikachu()
# 隐藏画笔
turtle.hideturtle()
# 保持窗口不关闭
turtle.done()
```
运行代码后,将会弹出一个窗口,里面绘制了皮卡丘。你也可以调整代码中的参数来修改皮卡丘的大小和位置。
阅读全文