Python表白玫瑰花绘制教程:六一儿童节特别版

一年一度的儿童节即将来了,相信各位小哥哥小姐姐们也会触景生情,想到自己儿时快乐情景,想起当年坐在同桌的她/他。

今天教大家一招,帮你将儿时的童年女神/男神追到手。

废话不多说,安排!!!

一、玫瑰花绘制—深红色

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

# 将相位向后移动了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= 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()

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空