python绘制草莓熊

import matplotlib.pyplot as plt
import numpy as np

# 绘制草莓熊的圆形身体
x, y = np.meshgrid(np.linspace(-1, 1, 100), np.linspace(-1, 1, 100))
circle = x**2 + y**2 < 0.8
plt.imshow(circle, cmap='gray')

# 绘制草莓熊的耳朵,由两个圆组成
ear1 = (x - 0.5)**2 + (y + 0.5)**2 < 0.3
ear2 = (x + 0.5)**2 + (y + 0.5)**2 < 0.3
ear = np.logical_or(ear1, ear2)
plt.imshow(ear, cmap='gray')

# 绘制草莓熊的眼睛,由两个圆组成
eye1 = (x - 0.3)**2 + (y + 0.2)**2 < 0.05
eye2 = (x + 0.3)**2 + (y + 0.2)**2 < 0.05
eye = np.logical_or(eye1, eye2)
plt.imshow(eye, cmap='gray')

# 绘制草莓熊的鼻子,由一个圆和一个半弧组成
nose1 = (x - 0.1)**2 + y**2 < 0.05
nose2 = y < 0 and x < 0.2 and x > -0.2
nose = np.logical_or(nose1, nose2)
plt.imshow(nose, cmap='gray')

# 绘制草莓熊的嘴巴,由一条弧组成
mouth = x**2 + (y - 0.4)**2 < 0.2
plt.imshow(mouth, cmap='gray')

# 绘制草莓熊的手臂,由两个半弧和一个短线组成
arm1 = y < -0.3 and x > 0 and (x - 0.2)**2 + (y + 0.3)**2 > 0.1
arm2 = y < -0.3 and x < 0 and (x + 0.2)**2 + (y + 0.3)**2 > 0.1
arm3 = y < -0.4 and x < 0.2 and x > -0.2
arm = np.logical_or(arm1, arm2)
arm = np.logical_or(arm, arm3)
plt.imshow(arm, cmap='gray')

# 添加草莓图案
strawberry = x**2 + (y - 0.8)**2 < 0.2
plt.imshow(strawberry, cmap='pink')

# 添加标题和显示图片
plt.title('Strawberry bear')
plt.show()

草莓熊,其身体由一个圆形组成,耳朵、眼睛、鼻子、嘴巴和手臂由圆和弧线组成,而草莓图案由一个圆组成。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2023年10月17日
下一篇 2023年10月17日

相关推荐