Creating fractals with the chaos game
Go to file
Mattéo Delabre 6d6af1092d 🐛 Full ES6 => ES5 transpiling 2015-12-21 23:50:48 +01:00
images 💡 Add avatar 2015-12-12 01:12:04 +01:00
scripts 💡 Use `the-dom` 2015-12-21 23:37:34 +01:00
styles 💡 Update style 2015-12-16 23:05:25 +01:00
.gitignore 🐛 Checkout bundle.js 2015-12-21 23:38:53 +01:00
LICENSE 📖 Change LICENSE to CC-0 2015-12-11 20:22:42 +01:00
README.md 📖 Fix typo 2015-01-29 21:49:00 +01:00
bundle.js 🐛 Full ES6 => ES5 transpiling 2015-12-21 23:50:48 +01:00
index.html 💡 Update site structure 2015-12-16 23:05:00 +01:00
package.json 🐛 Full ES6 => ES5 transpiling 2015-12-21 23:50:48 +01:00

README.md

Chaos game app

A Javascript web app that allows you to test the "Chaos game" algorithm that consists in a few steps:

  1. take a n-vertices polygon (in the app, there is only regular polygons, but it is possible to use scalenous ones);
  2. choose a random point (out or inside the polygon);
  3. choose a random vertex;
  4. take the middle of the segment vertex-point (other factors can also be used);
  5. go to step 2. using the middle point.

This game was created by Michael Barnsley and was described in his book Fractals everywhere in 1993. When using a triangle and a factor 1/2, you get the Sierpinski's triangle. Other fractal forms can also be plotted using other settings. Most common settings are present in the "Presets" section in the app.

Technical details

This experiment made me try several ways of drawing a lot of points on a canvas element. Actually, the coordinates of the points are calculated in a separate thread using Workers (js/lib/chaos.js), and then plotted using putDataImage. I wrote some performance tests here and the result is that this method is about 100x faster.

Points of a regular polygon are calculated using a circle and a loop that iterates along it (angle per angle). Using trigonometric functions, we can then retrieve the actual coordinates of these points (more in the js/lib/script.js file).

More on Michael Barnsley
More on Chaos game
See the app