donotturnoff

Chaos game

Introduction

The chaos game is an intriguing process which produces a familiar but surprising output. I first learned about it from a Numberphile video and decided to write a program to do it for me.

The idea is that you pick three fixed points anywhere in the plane (don't put them in a line because that wouldn't be very interesting), then pick another random point somewhere else to start from. Then choose one of the three fixed points at random, and move halfway from the start point to that point. This is your new start point. Pick another one at random, and move halfway towards that one, the repeat the process ad infinitum. Very soon an interesting pattern begins to emerge (you've probably already spotted the screenshot below).

For more than three points, you should change the ratio (e.g. move 0.4 of the way) or apply further restrictions to get interesting patterns - for example, with four points, you can get an interesting pattern if, when picking a point to move to, you don't let yourself pick the point which you chose previously.

Files

Screenshots

Related projects

Further reading