欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

Python绘制3D立体花朵示例详解

时间:2023-01-22 11:44:38|栏目:Python代码|点击:

动态展示

这是一个动态图哦

导读

兄弟们可以收藏一下哦!情人节可以送出去,肥学找了几朵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)


效果图

上一篇:Flask项目的部署的实现步骤

栏    目:Python代码

下一篇:浅谈python中scipy.misc.logsumexp函数的运用场景

本文标题:Python绘制3D立体花朵示例详解

本文地址:http://www.codeinn.net/misctech/224188.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有