# The Chaos Game

The "Chaos Game" isn't actually a game per se -- it is, however, an amazingly simple way to visualize a strange attractor for an iterated function system. Sound complicated? Don't worry, it's not. Here are the "rules" of the game:

1. Mark three points on a sheet of paper that could be the vertices of some triangle (i.e., they can't be collinear).

2. Now pick a random point $P$ and draw a dot at its location.

3. Find the midpoint between point $P$ and one of the aforementioned three vertices, chosen at random. Draw another dot at this midpoint, and let this become the new point $P$.

4. Repeat step (iii) many, many times (at least a thousand, maybe more).

Given the number of points that must be drawn, playing this game on an actual sheet of paper can actually be somewhat tedious -- so let's get a computer to do the grunt work! Write a class named ChaosGamePlotter that extends the OneButtonBreadboard class that implements the "game" described above, using the following guidelines:

1. Use GOval objects from the ACM libraries to draw the three vertices and all of the various points $P$. Draw the three vertices as circles with radius 4, and draw the points $P$ as circles with radius $0.5$.

2. For aesthetic reasons, make the triangle discussed equilateral, pointing up, and of a size that is as large as possible while still leaving an empty margin 40 units wide at the top and bottom of the central drawing area. (That said, you might want to experiment with what happens when the vertices are chosen to be in different locations...)

3. Between plotting the various points $P$, pause briefly (like 4 milliseconds) -- this will create a more dramatic animated effect. (If you need to, you can repaint the screen by calling this.paintBreadboardCanvas()).

4. The number of times you find and plot a new point $P$ should be determined by whatever number the user enters in the text field at the bottom of the window.

5. The vertices should be drawn as soon as the program runs, but the points $P$ shouldn't be plotted until the user clicks the "Go" button. If the user clicks the "Go" button again, the old points $P$ should be removed from the screen (a call to this.removeAll() should do this), and a new initial point $P$ should be chosen at random.

Check out the video below to see this program in action... 