In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how Python uses Koch curve to achieve three-dimensional snow effect, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
Random snowflake
If you randomly generate some points, and then draw some branches for each point, you can draw a structure similar to dandelion, but it doesn't look very good.
Import numpy as npimport matplotlib.pyplot as pltfrom numpy.random import rand,randintM,N = 10100x = rand (N) * 100y = rand (N) * 100plt.scatter (x [I], x [I] + r*np.cos (theta)] for i in range (N): M = randint (5, 15) r = rand () * 3 for j in range (M): theta = np.pi*2/M*j plt.plot ([x [I], x [I] + r*np.cos (theta)] [y [I], y [I] + r*np.sin (theta)]) plt.axis ('off') plt.show ()
Of course, it can also be drawn into a three-dimensional picture, and it is still very ugly.
Koch snowflakes
So, since you want to snow, you must first have snowflakes. Koch curve is also called snowflake curve because it is very similar to snowflake. The generation method is very simple, which is divided into two steps.
Draw a regular triangle to divide each side of the regular triangle equally, then take the middle part as the side, and then draw a triangle. Repeat step two.
So the difficulty is nothing more than how to draw a new triangle after the third division, and further, where is the new vertex of the new triangle?
In order to get
The code is as follows
Import numpy as npimport matplotlib.pyplot as pltfrom numpy.random import rand,randint# n > = 1, the method of generating Koch snowflakes def Koch (LMaginnum 1): if n
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.