python绘制简笔画大象
时间: 2024-10-20 10:13:00 浏览: 24
Python中可以利用matplotlib库或者PIL(Pillow)库来绘制简单的图形,这里我将展示一种使用matplotlib绘制简笔画大象的方法。由于文本形式有限,我会给出一个基础的示例,你可以通过调整颜色、线条粗细等属性来丰富效果。
```python
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, Rectangle, Arc
# 定义颜色和尺寸
body_color = 'gray'
eye_color = 'black'
nose_color = 'red'
# 创建figure和axes
fig, ax = plt.subplots()
# 绘制身体
body_radius = 50
body = Circle((150, 200), body_radius, fill=False)
ax.add_patch(body)
# 绘制耳朵
ear_width = 80
ear_height = 60
left_ear = Rectangle((120, 190), ear_width, ear_height, angle=-45, fill=False)
right_ear = Rectangle((220, 190), ear_width, ear_height, angle=45, fill=False)
ax.add_patch(left_ear)
ax.add_patch(right_ear)
# 绘制眼睛
eye_diameter = 20
eye_left = Circle((170, 160), eye_diameter / 2, color=eye_color)
eye_right = Circle((230, 160), eye_diameter / 2, color=eye_color)
ax.add_patch(eye_left)
ax.add_patch(eye_right)
# 绘制鼻子
nose_length = 70
nose_line = [150 + nose_length * np.cos(np.radians(-45)), 200 + nose_length * np.sin(np.radians(-45))]
nose_tip = [150 + nose_length * np.cos(np.radians(0)), 200 + nose_length * np.sin(np.radians(0))]
nose = plt.Line2D(nose_line, color=nose_color)
ax.add_line(nose)
# 显示图像
plt.show()
阅读全文