Python是一種廣泛應用于數據科學、人工智能等領域的編程語言,它也可以用于繪圖。那么,我們可以使用Python來繪制我們喜歡的魏無羨的畫像。
# 導入相關庫 import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Ellipse # 創建一個畫布 fig, ax = plt.subplots() # 繪制頭部 ellipse_face = Ellipse(xy=(0, 0), width=0.7, height=1, edgecolor='black', facecolor='#FAD29A') ax.add_patch(ellipse_face) # 繪制眼睛 ellipse_left_eye = Ellipse(xy=(-0.35, 0.1), width=0.25, height=0.5, edgecolor='black', facecolor='white') ax.add_patch(ellipse_left_eye) ellipse_right_eye = Ellipse(xy=(0.35, 0.1), width=0.25, height=0.5, edgecolor='black', facecolor='white') ax.add_patch(ellipse_right_eye) # 繪制瞳孔 circle_left_pupil = plt.Circle((-0.35, 0.1), 0.1, color='black') ax.add_patch(circle_left_pupil) circle_right_pupil = plt.Circle((0.35, 0.1), 0.1, color='black') ax.add_patch(circle_right_pupil) # 繪制鼻子 nose = plt.Polygon([(0, 0.1), (-0.1, 0), (0.1, 0)], closed=True, edgecolor='black', facecolor='#FAD29A') ax.add_patch(nose) # 繪制嘴巴 mouth = plt.Polygon([(-0.2,-0.3), (0,-0.2), (0.2,-0.3)], closed=True, edgecolor='black', facecolor='#F77272') ax.add_patch(mouth) # 繪制臉龐 ellipse_face_1 = Ellipse(xy=(0, -0.6), width=1.25, height=1.7, angle=0, edgecolor='black', facecolor='#FAD29A') ax.add_patch(ellipse_face_1) # 繪制耳朵 ear_left = plt.Polygon([(-0.7,0.3),(-0.4,0.4),(-0.5,0)], closed=True, edgecolor='black', facecolor='#FAD29A') ax.add_patch(ear_left) ear_right = plt.Polygon([(0.4,0.4),(0.7,0.3),(0.5,0)], closed=True, edgecolor='black', facecolor='#FAD29A') ax.add_patch(ear_right) # 設置畫布的范圍和坐標軸 plt.xlim([-1, 1]) plt.ylim([-1.8, 1]) plt.axis('off') # 顯示圖片 plt.show()
運行以上代碼,就可以得到我們所繪制的魏無羨畫像了。實際上,許多我們喜歡的畫像都可以使用Python進行繪制,而這個過程也可以是十分有趣的。