python表白玫瑰花繪制——六一兒童節(jié)女神秒變你的小朋友

一年一度的兒童節(jié)即將來了,相信各位小哥哥小姐姐們也會(huì)觸景生情,想到自己兒時(shí)快樂情景,想起當(dāng)年坐在同桌的她/他。

今天教大家一招,幫你將兒時(shí)的童年女神/男神追到手。

廢話不多說,安排?。。?/p>

一、玫瑰花繪制—深紅色

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

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= plt.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)

plt.show()

#源碼可以簡信我喲~

二、玫瑰花繪制—五顏六色

import numpy as np

import matplotlib.pyplot as plt

from matplotlib import cm

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

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))

h = u * (x * np.cos(p) - y * np.sin(p))

c= cm.gist_rainbow_r

surf = ax.plot_surface(r * np.cos(t), r * np.sin(t), h, rstride=1, cstride=1,

? ? ? ? ? ? ? ? ? ? ? cmap= c, linewidth=0, antialiased=True)

plt.show()

三、玫瑰花繪制—粉紅色

import numpy as np

import matplotlib.pyplot as plt

from matplotlib import cm

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

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))

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)

plt.show()

四、玫瑰花繪制—紅色

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

ax = fig.gca(projection='3d')

# 將相位向后移動(dòng)了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))

# 添加邊緣擾動(dòng)

change = np.sin(15*t)/150

# 將t的參數(shù)減少,使花瓣的角度變大

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= plt.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)

plt.show()

五、桃花繪制

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

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= plt.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)

plt.show()

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容