您好,登錄后才能下訂單哦!
本篇內容主要講解“Python怎么繪制3D立體花朵”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Python怎么繪制3D立體花朵”吧!
這是一個動態圖哦
兄弟們可以收藏一下哦!情人節可以送出去,肥學找了幾朵python寫的花給封裝好送給大家。不是多炫酷但是有足夠的用心哦。別忘了點贊呀我也就不細說了,來吧展示!
def lotus(): fig = plt.figure(figsize=(10,7),facecolor='black',clear=True) ax = fig.gca(projection='3d') [x, t] = np.meshgrid(np.array(range(25))/24.0, np.arange(0, 575.5, 0.5)/575 * 17 * np.pi-2*np.pi) p = (np.pi/2)*np.exp(-t/(8*np.pi)) u = 1-(1-np.mod(3.6*t, 2*np.pi)/np.pi)**4/2 y = 2*(x**2-x)**2*np.sin(p) r = u*(x*np.sin(p)+y*np.cos(p)) surf = ax.plot_surface(r*np.cos(t), r*np.sin(t), u*(x*np.cos(p)-y*np.sin(p)), rstride=1, cstride=1, cmap=cm.gist_rainbow_r, linewidth=0, antialiased=True)
效果圖
def rose_flower(): fig = plt.figure(figsize=(10,7),facecolor='black',clear=True) ax = fig.gca(projection='3d') # 將相位向后移動了6*pi [x, t] = np.meshgrid(np.array(range(25)) / 24.0, np.arange(0, 575.5, 0.5) / 575 * 20 * np.pi + 4*np.pi) p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) # 添加邊緣擾動 change = np.sin(15*t)/150 # 將t的參數減少,使花瓣的角度變大 u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi) ** 4 / 2 + change y = 2 * (x ** 2 - x) ** 2 * np.sin(p) r = u * (x * np.sin(p) + y * np.cos(p)) h = u * (x * np.cos(p) - y * np.sin(p)) c= cm.get_cmap('Reds') surf = ax.plot_surface(r * np.cos(t), r * np.sin(t), h, rstride=1, cstride=1, cmap= c, linewidth=0, antialiased=True)
效果圖
def peach_blossom(): fig = plt.figure(figsize=(10,7),facecolor='black',clear=True) ax = fig.gca(projection='3d') [x, t] = np.meshgrid(np.array(range(25)) / 24.0, np.arange(0, 575.5, 0.5) / 575 * 6 * np.pi - 4*np.pi) p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) change = np.sin(10*t)/20 u = 1 - (1 - np.mod(5.2 * t, 2 * np.pi) / np.pi) ** 4 / 2 + change y = 2 * (x ** 2 - x) ** 2 * np.sin(p) r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5 h = u * (x * np.cos(p) - y * np.sin(p)) c= cm.get_cmap('spring_r') surf = ax.plot_surface(r * np.cos(t), r * np.sin(t), h, rstride=1, cstride=1, cmap= c, linewidth=0, antialiased=True)
效果圖
def monthly_rose(): fig = plt.figure(figsize=(10,7),facecolor='black',clear=True) ax = fig.gca(projection='3d') [x, t] = np.meshgrid(np.array(range(25)) / 24.0, np.arange(0, 575.5, 0.5) / 575 * 30 * np.pi - 4 * np.pi) p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) change = np.sin(20 * t) / 50 u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi) ** 4 / 2 + change y = 2 * (x ** 2 - x) ** 2 * np.sin(p) r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5 h = u * (x * np.cos(p) - y * np.sin(p)) c = cm.get_cmap('magma') surf = ax.plot_surface(r * np.cos(t), r * np.sin(t), h, rstride=1, cstride=1, cmap=c, linewidth=0, antialiased=True)
效果圖
到此,相信大家對“Python怎么繪制3D立體花朵”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。