Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw 3D Flowers with Python

Shulou Source: shulou.com Published: 2022-06-02 09:07:15 10月04日 Update

This article mainly explains "how to draw 3D flowers with Python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to draw 3D flowers with Python.

Dynamic display

This is a dynamic graph.

Guide reading

Brothers can collect it! You can give it away on Valentine's Day. Feixue found some flowers written by python to be encapsulated and given to everyone. Not so cool, but with enough heart. Don't forget to like it. I won't go into details. Come on, show it!

Source code and detailed explanation of Lotus def lotus (): fig = plt.figure (figsize= (10L7), facecolor='black',clear=True) ax = fig.gca (projection='3d') [x, t] = np.meshgrid (np.array (range (25)) / 24.0, np.arange (0, 575.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%) 2*np.pi) / np.pi) * * 4Accord 2 y = 2 * (xanthates 2y*np.sin 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)

Effect picture

Rose def rose_flower (): fig = plt.figure (figsize= (10P7), facecolor='black',clear=True) ax = fig.gca (projection='3d') # shifts the phase backward 6*pi [x, t] = np.meshgrid (np.array (range (25)) / 24.0, np.arange (0, 575.5) ) / 575 * 20 * np.pi + 4*np.pi) p = (np.pi / 2) * np.exp (- t / (8 * np.pi)) # add edge disturbance change = np.sin (15 * t) / 150 # to reduce the parameters of t Enlarge the angle of petals u = 1-(1-np.mod (3.3t) 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)

Effect picture

Peach blossom 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) 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.5h = 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)

Effect picture

Rose def monthly_rose (): fig = plt.figure (figsize= (10P7), facecolor='black',clear=True) ax = fig.gca (projection='3d') [x, t] = np.meshgrid (np.array (range (25)) / 24.0, np.arange (0, 575.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.5h = 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)

Effect picture

At this point, I believe you have a deeper understanding of "how to draw 3D flowers with Python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Effects effect drawings stereo flowers content dynamic learning practical deeper brothers interests parameters practicality practicality lover simple operation methods more rose friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB OPPO Reno NVidia Shulou Tech Info