Python绘制3D立体花朵示例详解
作者:肥学 时间:2021-06-26 02:59:54
动态展示
这是一个动态图哦
导读
兄弟们可以收藏一下哦!情人节可以送出去,肥学找了几朵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)
效果图
来源:https://blog.csdn.net/jiahuiandxuehui/article/details/119682634
标签:Python,3D,花朵
0
投稿
猜你喜欢
python实现矩阵乘法
2023-11-03 07:41:10
使用llama Index帮你训练pdf的示例详解
2023-07-30 23:00:33
Python读取txt内容写入xls格式excel中的方法
2023-08-31 22:29:17
深入理解Python爬虫代理池服务
2022-11-05 17:20:29
交互设计实用指南系列(5) – 突出重点,一目了然
2010-01-11 21:05:00
Thinkphp模板中使用自定义函数的方法
2024-05-13 09:57:29
MySQL主从延迟现象及原理分析详解
2024-01-13 23:22:03
Nodejs之TCP服务端与客户端聊天程序详解
2024-05-03 15:55:48
django之常用命令详解
2023-02-04 07:25:19
Pytorch数据拼接与拆分操作实现图解
2021-08-01 04:37:05
在VS Code上搭建Python开发环境的方法
2021-02-19 14:20:38
Python如何实现FTP功能
2021-10-22 15:08:25
自然语言处理NLP TextRNN实现情感分类
2022-01-20 11:14:47
PHP 应用容器化以及部署方法
2023-11-14 15:45:06
python函数式编程学习之yield表达式形式详解
2022-12-31 05:55:15
Python手机与电脑游戏脚本的编写方法
2023-11-28 18:31:44
如何提高网页的维护效率
2009-03-01 11:33:00
python读取几个G的csv文件方法
2023-06-04 08:01:27
Python爬虫文件下载图文教程
2023-11-18 23:59:03
python文件拆分与重组实例
2021-10-10 18:10:25