In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to achieve the Sherbinsky triangle by Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve the Sherbinsky triangle by Python".
Sherbinsky triangle
The sierpinskr triangle is also a fractal structure, the plane is called the Sherpinski triangle, and the three-dimensional one is called the Sherbinsky pyramid.
The Serpinski triangle is understood to be a given triangle, which is stacked in the shape of "pin". The triangle side of each degree is half the length of the original triangle.
White part: blank
Black part: spliced sierpinskr triangle
Degree: degree, number of times stacked
This article is supported by "one partner Editor".
The idea of Sherbinsky's triangle drawing
According to self-similarity, the Serpinski triangle is made up of three sierpinskr triangles halved in size in the shape of "product".
When the degree is limited (the number of stacking is limited), the triangles of degree=n are stacked by three triangles of degree=n-1 in the shape of "product". At the same time, the sides of the triangles of the three degree=n-1 are half the length of the triangles of degree=n. When degree=0, it can no longer be stacked
Size reduction: the triangle side length of degree=n-1 is half that of degree=n triangle.
Basic end condition: degree=0 (no more splicing)
Function parameter settings:
Points = {'left': (x, y),' top': (x, y), 'right': (x, y)}
Points is a dictionary that stores the coordinates of three points of a triangle. Each coordinate is another tuple.
Drawing order:
Draw the left triangle first
And draw a triangle.
Finally draw the triangle on the right.
Triangle drawing order:
First trace the left point of the triangle left
Retrace triangle vertices top
Finally, right, the right point of the triangle.
This article is supported by "one partner Editor".
Code
Running result:
Recursive understanding
Recursion can be understood as a loop, and if a recursive call is followed by a program, it can be understood as the nesting of a loop. At the end of the current recursive loop, the program jumps to the upper loop of the basic end condition to continue with the rest of the program
Thank you for your reading, the above is the content of "how to achieve the Sherbinsky triangle in Python". After the study of this article, I believe you have a deeper understanding of how to achieve the Sherpinski triangle in Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.