Python_2  1.0
Functions
_16_sierpinski_gasket Namespace Reference

Draws a Sierpinski Gasket. More...

Functions

def Sierpinski (a, b, c, n, fourth=False)
 Creates a Sierpinski Gasket, by recursively partitioning an initial triangle (a,b,c) into three or four new triangles. More...
 
def draw (c, points, contour=False)
 Draw triangles, given in points, on canvas c. More...
 
def main (argv=None)
 Main program. More...
 

Detailed Description

Draws a Sierpinski Gasket.

Usage: _16_sierpinski [number_of_divisions]

Author
Paulo Roma Cavalcanti
Since
09/02/2016
See also
http://paulbourke.net/fractals/polyhedral/
https://en.wikipedia.org/wiki/Sierpinski_triangle
http://ecademy.agnesscott.edu/~lriddle/ifs/siertri/siertri.htm
http://www.oftenpaper.net/sierpinski.htm
https://code.activestate.com/recipes/580614-sierpinski-gasket/

Function Documentation

◆ draw()

def _16_sierpinski_gasket.draw (   c,
  points,
  contour = False 
)

Draw triangles, given in points, on canvas c.

Referenced by main().

◆ main()

def _16_sierpinski_gasket.main (   argv = None)

Main program.

References draw(), _08b_clock_bezier.resize, and Sierpinski().

◆ Sierpinski()

def _16_sierpinski_gasket.Sierpinski (   a,
  b,
  c,
  n,
  fourth = False 
)

Creates a Sierpinski Gasket, by recursively partitioning an initial triangle (a,b,c) into three or four new triangles.

  • There will be:
    • \(3^{n}\) red triangles or
    • \(4^{n}\) if the fourth triangle is drawn.
  • The number of white triangles is a Geometric Progression, starting at 1 and with ratio 3, given by:
    • P(0) = 0
    • P(n) = 3 * P(n-1) + 1
    • P(n) = \(\frac{(3^n-1)}{2}.\)
Parameters
afirst vertex coordinates.
bsecond vertex coordinates.
cthird vertex coordinates.
nnumber of subdivisions on each edge (depth of recursion).
fourthwhether to add the fourth triangle.

Referenced by main().