In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "using python to draw the moon and moon cake code examples". In the daily operation, I believe that many people have doubts about using python to draw the moon and moon cake code examples. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "using python to draw the moon and moon cake code examples". Next, please follow the editor to study!
Catalogue
One,? The moon
Two,? Snowflake moon cake
One,? The moon
Import libraries matplotlib and numpy for direct use as tools.
From mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltimport numpy as np
Overall Arrangement
Create a long × wide canvas size
Fig = plt.figure (figsize= (1010))
Layout of 3D viewing angle
Ax = fig.add_subplot (121, projection='3d')
Generate the data of the isometric sequence and draw a sphere
X = np.linspace (0,2 * np.pi) y = np.linspace (0,2 * np.pi) x1 = 10 * np.outer (np.cos (x), np.sin (y)) y1 = 10 * np.outer (np.sin (x), np.sin (y)) z = 10 * np.outer (np.ones (np.size (x1)), np.cos (y1)) ax.plot_surface (x1, y1, z, color='yellow')
At this time, we found that there was only one moon, so we planned to draw the second moon and form a pair.
Ax = fig.add_subplot (122,100) x = np.linspace (0,2 * np.pi) y = np.linspace (0,np.pi, 100) x1 = 10 * np.outer (np.cos (x), np.sin (y)) y1 = 10 * np.outer (np.sin (x), np.sin (y)) z = 10 * np.outer (np.ones (np.size (x1)), np.cos (y1) ax.plot_surface (x1, y1, z) Color='r')
Effect picture
It's all right ~ ha!
Two,? Snowflake moon cake
To import the required libraries, most of them are written by turtle.
Import turtleimport time
Let's draw a bottom yellow cake as the bottom.
Def circle (): fillX_y (0,0) turtle.color ("# F0E68C") for _ in range (30): turtle.left (12) turtle.begin_fill () turtle.forward (230) turtle.circle (25,180) turtle.goto (0,0) turtle.left (180) turtle.end_fill () time.sleep
Since it is a snowflake moon cake, there should be snowflakes. Next, let's draw snowflakes.
Koch curve is used to draw snowflakes. To change the degree of bending.
Def koch (size, n): # defines a curved line to make it angular if n = 0: turtle.fd (size) else: for angle in [0,60,120,60]: # change it at a reasonable angle each time turtle.left (angle) koch (size / 3, n-1)
Because I'm going to draw eight and add colors, so colorful snowflakes ~
If a = 1: turtle.color ("black") # controls the brush color elif a = = 2: turtle.color ("purple") elif a = = 3: turtle.color ("blue") elif a = = 4: turtle.color ("Cyan") elif a = = 5: turtle.color ("green") elif a = = 6: turtle.color ("yellow") elif a = 7: turtle.color ("orange") elif a = 8: turtle.color ("red")
Since it is nested by eight snowflakes, a proportionally scaled package is required.
Turtle.penup () turtle.goto (- 200 * (4 / 7) * * (s-n), 100 * (4 / 7) * * (s-n)) # each time it is necessary to expand or shrink turtle.pendown () turtle.pensize (2) level = 5koch (400 * (4 / 7) * (s-n), level) # is a trial # that cannot exceed the set range of setup Otherwise, turtle.right (120,400) koch (400 * (4 / 7) * * (s-n), level) turtle.right (120) koch (400,400 * (4 / 7) * * (s-n), level) # Note here koch has to turn the angle turtle.right (120) turtle.hideturtle () # Hidden brush flower (n-1)
Effect picture! Ah ha! It's a snowflake moon cake!
At this point, the study on "using python to draw examples of the moon and moon cake code" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.