fractals.sierpinski_triangle¶
Author Anurag Kumar | anuragkumarak95@gmail.com | git/anuragkumarak95
Simple example of fractal generation using recursion.
- What is the Sierpiński Triangle?
The Sierpiński triangle (sometimes spelled Sierpinski), also called the
Sierpiński gasket or Sierpiński sieve, is a fractal attractive fixed set with the overall shape of an equilateral triangle, subdivided recursively into smaller equilateral triangles. Originally constructed as a curve, this is one of the basic examples of self-similar sets—that is, it is a mathematically generated pattern that is reproducible at any magnification or reduction. It is named after the Polish mathematician Wacław Sierpiński, but appeared as a decorative pattern many centuries before the work of Sierpiński.
Usage: python sierpinski_triangle.py <int:depth_for_fractal>
- Credits:
The above description is taken from https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle This code was written by editing the code from https://www.riannetrujillo.com/blog/python-fractal/
Attributes¶
Functions¶
|
Find the midpoint of two points |
|
Recursively draw the Sierpinski triangle given the vertices of the triangle |
Module Contents¶
- fractals.sierpinski_triangle.get_mid(p1: tuple[float, float], p2: tuple[float, float]) tuple[float, float] ¶
Find the midpoint of two points
>>> get_mid((0, 0), (2, 2)) (1.0, 1.0) >>> get_mid((-3, -3), (3, 3)) (0.0, 0.0) >>> get_mid((1, 0), (3, 2)) (2.0, 1.0) >>> get_mid((0, 0), (1, 1)) (0.5, 0.5) >>> get_mid((0, 0), (0, 0)) (0.0, 0.0)
- fractals.sierpinski_triangle.triangle(vertex1: tuple[float, float], vertex2: tuple[float, float], vertex3: tuple[float, float], depth: int) None ¶
Recursively draw the Sierpinski triangle given the vertices of the triangle and the recursion depth
- fractals.sierpinski_triangle.my_pen¶