The code for producing all of these renders is available on GitHub.

The rendering of the images is done using POV-Ray. In previous simulations of chaotic attractors, I have performed the calculations directly in POV-Ray. For this project, however, I separated out the calculation of the data points from the rendering of the image. This allowed me to be able to make small changes to the render settings without having to recalculate 10,000,000 data points.

I wrote a small C# console application that plays the chaos game over many iterations and outputs two text files:

  • A small text file with co-ordinates and colours of all the anchor points
  • A big text file with co-ordinates and colours of all the calculated data points

The files contain a series of vectors in the form:

    <-1,-1,0>,<1,0,0>,<1,-1,0>,<0,1,0>,<0,1,0>,<0,0,1>
    
For each data point, there is a pair of vectors. The first vector is the 'x,y,z' position of the point, while the second vector is the 'r,g,b' value of the colour.

This example is for the anchor points of a triangle, coloured red, green and blue respectively. The data points file is exactly the same logic, but for a much bigger set of points.

This format was chosen because it was simple to read in to POV-Ray. However, if one can configure a different rendering engine to read these same files, one could swap out POV-Ray entirely.

The POV-Ray file simply contains a camera and some lights, and reads the anchors file to render the anchors as coloured spheres and then reads the data points and renders each one as a tiny sphere. There are numerous settings associated with both the render and the calculation, which we'll get to later.

Code

The code is executed from Program.cs, where you can set up your shapes.

As a simple example,
    private static void Main(string[] args)
    {          
        var p = new Polygon(3);  
        p.StartRender();
    }
    					
This will create a regular polygon with 3 anchor points (a triangle) and then play the chaos game using all the default settings.

Executing this should create a folder within the /bin/Debug folder called '3-gon' within which there should be four files:

3-gon_r0.5_p10-datapoints.txt
The series of XYZ co-ordinates and RGB values of the calculated points from playing the chaos game
3-gon-anchors.txt
The series of XYZ co-ordinates and RGB values of the initial anchor points
3-gon_r0.5_p10-datapoints.txt.pov
The scene setup
3-gon_r0.5_p10-datapoints.txt.pov.ini
The animation setup

The program will only output these files. You will need to open the .pov or the .ini file in POV-Ray and execute to start the render.