Learning Scientific Programming with Python (2nd edition)

P7.5.1: The Chaos Game

Question P7.5.1

The so-called chaos game is an algorithm for generating a fractal. First define the $n$ vertices of a regular polygon and an initial point, $(x_0,y_0)$, selected at random within the polygon. Then generate a sequence of points, starting with $(x_0, y_0)$, where each point is a fraction $r$ of the distance between the previous one and a polygon vertex chosen at random.

Write a program to draw fractals using the chaos game algorithm and test it with values $n=3, r=0.5$.