Python画线条小狗
时间: 2024-09-02 15:00:32 浏览: 276
Python可以使用matplotlib库来绘制简单的线条小狗图形。虽然没有直接内置小狗形状,但我们可以结合一些基础图形元素来创造类似的效果。以下是一个简单的例子,使用矩形、圆形和直线来构造一个基础的小狗形状:
```python
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle, Circle
# 定义小狗的尺寸和位置
width = 5
height = 7
body_pos = (50, 50)
head_pos = (40, 65)
eye_pos1 = (45, 60)
eye_pos2 = (45, 70)
tail_pos = (75, 30)
def draw_dog(ax):
# 身体部分
body = Rectangle(body_pos, width, height, fill=False)
ax.add_patch(body)
# 头部
head = Rectangle(head_pos, 8, 10, angle=45, fill=False)
ax.add_patch(head)
# 眼睛
eye1 = Circle(eye_pos1, 5, fill=True, color='black')
eye2 = Circle(eye_pos2, 5, fill=True, color='black')
ax.add_patch(eye1)
ax.add_patch(eye2)
# 鼻子
nose = Rectangle((head_pos[0] + 3, head_pos[1] + 4), 3, 2, fill=True, color='red')
ax.add_patch(nose)
# 尾巴
tail = Rectangle(tail_pos, 10, 10, angle=-45, fill=False)
ax.add_patch(tail)
# 连接眼睛和鼻子
line1 = ax.plot([eye_pos1[0], nose.centerx], [eye_pos1[1], nose.centery], 'k-', linewidth=2)[0]
line2 = ax.plot([eye_pos2[0], nose.centerx], [eye_pos2[1], nose.centery], 'k-', linewidth=2)[0]
ax.set_xlim(0, 100)
ax.set_ylim(0, 100)
ax.axis('off')
fig, ax = plt.subplots()
draw_dog(ax)
plt.show()
阅读全文