程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python繪制玫瑰花情人節表白

編輯:Python

目錄

一、玫瑰花繪制—深紅色

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

三、玫瑰花繪制—粉紅色

四、玫瑰花繪制—紅色

五、桃花繪制

一、玫瑰花繪制—深紅色

import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfig = 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)/50u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi) ** 4 / 2 + changey = 2 * (x ** 2 - x) ** 2 * np.sin(p)r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5h = 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 npimport matplotlib.pyplot as pltfrom matplotlib import cmfrom mpl_toolkits.mplot3d import Axes3Dfig = 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 / 2y = 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_rsurf = 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 npimport matplotlib.pyplot as pltfrom matplotlib import cmfrom mpl_toolkits.mplot3d import Axes3Dfig = 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 / 2y = 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 npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfig = 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 + changey = 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 npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfig = 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)/20u = 1 - (1 - np.mod(5.2 * t, 2 * np.pi) / np.pi) ** 4 / 2 + changey = 2 * (x ** 2 - x) ** 2 * np.sin(p)r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5h = 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()

到此這篇關於python繪制玫瑰花情人節表白的文章就介紹到這了,更多相關python繪制玫瑰花內容請搜索軟件開發網以前的文章或繼續浏覽下面的相關文章希望大家以後多多支持軟件開發網!



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved