This project provides a script generating the Sierpinski triangle, a fractal.
The way it is obtained is of particular interest:
- start by drawing 3 points, the vertices of a triangle
- draw a 4th point wherever you want (better on the inner surface of the triangle)
- randomly chose a vertex and draw a point exactly at half distance between the last point drawn and the vertex chosen
- repeat the operation as much time as you want and you'll always obtain the fractal image
- main.py
This file contains the main program.
You can choose the starting point and the number of total points drown by editing
the attributes start_pt
and total_pt
. You can also select a different color
through the color
attribute for a bunch of things: the colors available are listed
in the module colors.py
. If the color provided doesn't exist or no color is provided,
every point will have a random color from the ones of the module above mentioned.
- colors.py
This file contains a dictionary and a list with 9 of the main RGB colors.
The structs can be extended by adding extra colors.
The program requires Pillow
and random
modules to execute.
background_color = c.colors_dict['black'] # set the background color
start_pt = (560, 380) # set the position of the first point
start_pt_color = c.colors_dict['white'] # set its color
color = 'lime' # set the color for all others point
total_pt = 1000000 # set the number of points to draw
The result should look like this: