import matplotlib.pyplot as pltimport numpy as np# 绘制草莓熊的圆形身体x, y = np.meshgrid(np.linspace(-1, 1, 100), np.linspace(-1, 1, 100))circle = x**2 + y**2 < 0.8plt.imshow(circle, cmap='gray')# 绘制草莓熊的耳朵,由两个圆组成ear1 = (x - 0.5)**2 + (y + 0.5)**2 < 0.3ear2 = (x + 0.5)**2 + (y + 0.5)**2 < 0.3ear = np.logical_or(ear1, ear2)plt.imshow(ear, cmap='gray')# 绘制草莓熊的眼睛,由两个圆组成eye1 = (x - 0.3)**2 + (y + 0.2)**2 < 0.05eye2 = (x + 0.3)**2 + (y + 0.2)**2 < 0.05eye = np.logical_or(eye1, eye2)plt.imshow(eye, cmap='gray')# 绘制草莓熊的鼻子,由一个圆和一个半弧组成nose1 = (x - 0.1)**2 + y**2 < 0.05nose2 = y < 0 and x < 0.2 and x > -0.2nose = np.logical_or(nose1, nose2)plt.imshow(nose, cmap='gray')# 绘制草莓熊的嘴巴,由一条弧组成mouth = x**2 + (y - 0.4)**2 < 0.2plt.imshow(mouth, cmap='gray')# 绘制草莓熊的手臂,由两个半弧和一个短线组成arm1 = y < -0.3 and x > 0 and (x - 0.2)**2 + (y + 0.3)**2 > 0.1arm2 = y < -0.3 and x < 0 and (x + 0.2)**2 + (y + 0.3)**2 > 0.1arm3 = y < -0.4 and x < 0.2 and x > -0.2arm = np.logical_or(arm1, arm2)arm = np.logical_or(arm, arm3)plt.imshow(arm, cmap='gray')# 添加草莓图案strawberry = x**2 + (y - 0.8)**2 < 0.2plt.imshow(strawberry, cmap='pink')# 添加标题和显示图片plt.title('Strawberry bear')plt.show()
草莓熊,其身体由一个圆形组成,耳朵、眼睛、鼻子、嘴巴和手臂由圆和弧线组成,而草莓图案由一个圆组成。
来源地址:https://blog.csdn.net/m0_64611421/article/details/130947636