Chaos game

This is an interactive demonstration of the dynamical system called Chaos game. This game is "played" by following rules:

  1. Fix polygon Π
  2. Pick a random point P0
  3. Choose a random vertex V of the Π
  4. Set Pn+1 to the midpoint of the segment PnV [Note that the midpoint of the PnV has coordinates λ⋅(Pn + V), where λ = 0.5]
  5. Go back to step 3 and repeat

By repeating steps 3 and 4, you will get a set of points {P0, P1, P2, ...} which is called orbit. What is interesting about this game, is that no matter what point you pick in the second step, you will get "the same" picture after enough iterations.

In this demonstration, all points are treated as complex numbers. Also, the parameter λ is a complex number. By varying the parameter λ we can get more interesting pictures.

Control vertices of the polygon and value λ by dragging dots. Change the number of vertices with input at the bottom of screen.

If the Color option is selected, a point will be colored by the color of the vertex that was selected for that iteration.

Created by Nikola Ubavić • 2023 • Code available on Github.