怎么用python画皮卡丘
时间: 2023-09-13 21:09:57 浏览: 89
可以使用Matplotlib库来绘制皮卡丘。以下是一个简单的代码示例:
```python
import matplotlib.pyplot as plt
import numpy as np
# 画出圆形
def draw_circle(center, radius, color):
x = np.linspace(center[0]-radius, center[0]+radius, 100)
y1 = center[1] + np.sqrt(radius**2 - (x-center[0])**2)
y2 = center[1] - np.sqrt(radius**2 - (x-center[0])**2)
plt.fill_between(x, y1, y2, color=color)
# 画出皮卡丘
def draw_pikachu():
# 脸
draw_circle(center=[0, 0], radius=1, color='#FEE12B')
draw_circle(center=[-0.3, 0.4], radius=0.2, color='white')
draw_circle(center=[0.3, 0.4], radius=0.2, color='white')
# 口
draw_circle(center=[0, -0.2], radius=0.4, color='black')
draw_circle(center=[0, -0.2], radius=0.35, color='#FEE12B')
# 眼睛
draw_circle(center=[-0.3, 0.4], radius=0.1, color='black')
draw_circle(center=[0.3, 0.4], radius=0.1, color='black')
draw_circle(center=[-0.3, 0.4], radius=0.05, color='white')
draw_circle(center=[0.3, 0.4], radius=0.05, color='white')
# 耳朵
draw_circle(center=[-0.7, 0.8], radius=0.25, color='#FEE12B')
draw_circle(center=[0.7, 0.8], radius=0.25, color='#FEE12B')
draw_circle(center=[-0.7, 0.8], radius=0.2, color='black')
draw_circle(center=[0.7, 0.8], radius=0.2, color='black')
# 身体
plt.fill_between([-1, 1], [-0.5, -0.5], [0.5, 0.5], color='#FEE12B')
draw_circle(center=[-0.5, 0], radius=0.4, color='black')
draw_circle(center=[0.5, 0], radius=0.4, color='black')
draw_circle(center=[-0.5, 0], radius=0.3, color='#FEE12B')
draw_circle(center=[0.5, 0], radius=0.3, color='#FEE12B')
# 手和脚
plt.fill_between([-1, -0.5], [-0.5, -0.9], [0.5, 0.1], color='#FEE12B')
plt.fill_between([1, 0.5], [-0.5, -0.9], [0.5, 0.1], color='#FEE12B')
# 绘制皮卡丘
draw_pikachu()
# 设置图形大小
plt.figure(figsize=(6, 6))
# 隐藏坐标轴
plt.axis('off')
# 显示图形
plt.show()
```
执行这段代码可以得到一个皮卡丘的图案。
阅读全文