niciki / Sierpinski_fractals

Chaos plot visualization of Sierpinski triangle (Sierpinski gasket) and Sierpinski square (Sierpinski carpet) using two different libraries (turtle and mathplotlib).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sierpinski fractals

Sierpinski triangle or Sierpinski gasket

Chaos plot visualization is done using two different libraries (turtle and mathplotlib). In the first visualization, the points are drawn sequentially, due to this, the speed is much lower than in the second method, where all the points are drawn together and the result is presented in the form of a picture. Attractor points are 3 vertices of the triangle. The number of points can be changed (it is necessary to change the value of the variable n).

Sample image for an image using the turtle module and n = 50000

image

Sample image for an image using the mathplot module and n = 100000

image

Sierpinski square or Sierpinski carpet

The algorithm is similar to drawing a Sierpinski triangle, but 8 points of attractors are used: 4 points of the apex of the square and midpoints of the sides.

Sample image for an image using the mathplot module and n = 1000000

image

Note

When using the variant that uses the mathplotlib library for large n (~> 100000), it is recommended to additionally specify specify the last additional line width parameter in ax.scatter, which can be made small, or even equal to zero, for example: linewidths = 0

An example of drawing a triangle for n = 10e7 without decreasing linewidth to 0

image

An example of drawing a triangle for n = 10e7 with decreasing linewidth to 0

image


Example of distribution of points with increasing n for a triangle

Гифка с Gifius ru

Example of distribution of points with increasing n for a square

Гифка с Gifius ru (6)

About

Chaos plot visualization of Sierpinski triangle (Sierpinski gasket) and Sierpinski square (Sierpinski carpet) using two different libraries (turtle and mathplotlib).


Languages

Language:Python 100.0%