The Chaos Game - Fractal Generation
by Lewis Kirby

This application allows you to play the "Chaos Game", which is a method for generating pretty fractal patterns. This is described in references 1 and 2 at the end of this help file, and is a neat way to create fractal images. The fractal is described graphically using Draw, then the Chaos application converts it into a textual description; this is then interpreted and the resulting fractal image appears before your eyes pixel by pixel. Further information on fractals is given in reference 3.

The best way to find out what the program does is to try it. First, run the Chaos application to place an icon on the icon bar. Next, open the directory !Chaos.DrawFiles which contains seven example Draw files for use with Chaos. Drag one of these Draw files to the Chaos icon (try the Gasket), and a text file will be created with the same name as the Draw file but with a ~ appended to the end (e.g. the Draw file Gasket will produce a text file called Gasket~). Now drag this text file to the Chaos icon and a large white window should appear, in which the fractal will gradually appear.

The Gasket Draw file contains a large triangle containing three smaller triangles. One way to understand the fractal generation for this file is as follows: in the Draw file we are saying that the main triangle actually consists of three copies of itself. That this is true is borne out by the final fractal image.

The Chaos icon has a single menu item: Quit. Choosing this quits the application. Clicking on the close icon of the Chaos Show window closes the window and discards the fractal image, but does not remove the icon.

GUIDE TO USE
------------
The program uses a sprite to draw to, and it is of fixed size, so the result will not look correct if the wrong mode is used. A suitable mode to use is mode 12.

The use of Draw means that the Chaos application is smaller than it might have been, but the picture in the Draw file must be created in the correct way. This means that the main part of the picture must be drawn first, and the transformed components drawn after. The items (main or components) may be transformed in any way allowed by using the "ears" at top right and bottom right of a selected object, or by menu items such as Reflect, X or Y scale, or Rotate. For the technical among you, the shear operation may be done using a combination of the ears. If the components of the drawing are grouped using the menu item Group in Draw (so that, for example, the whole diagram can be stretched or moved as a unit) then they must be Ungrouped before dragging into Chaos; if not then an error will be generated. In order that the final fractal fills the screen in the correct way, the drawing in Draw should be very close to the bottom left of the work area and should not go outside it anywhere.

Furthermore, if transformations occur in a single direction then the resulting fractal is unpredictable; it may be a single line of dots, or it may be a scattering of dots which go off the screen, or there may be nothing on screen at all. There is nothing that can be done about this; the program simply does not have enough information with which to determine the transformations.

When the Draw file is dropped into the Chaos icon, the file is transformed into a textual description of the transformations, which is placed in the text file. This may be edited if required and then dropped into the Chaos application. Note that the text file name does not have to end with ~ to be dropped into Chaos. The format of the text file is as follows: the first line contains the number of components; this is followed by one line per component, describing the transformation of that component. For the mathematically-minded, the transformation of the point (x,y) to (x',y') is given by the following matrix multiplication:

(x') = (a  b  c) (x)
(y')   (d  e  f) (y)
(1 )   (0  0  1) (1)

The application produces one line (i.e. one tranformation) for each component as: a b c d e f. For example, the file for the Gasket transformation above (called, incidentally, the Sierpinski gasket) is:
3
0.5 0 83  0 0.5 51 
0.5 0 310 0 0.5 394 
0.5 0 559 0 0.5 49 
 
The file must end with at least one empty line (i.e. there must be a line feed after the final 49); empty lines and spaces elsewhere in the file are ignored.

SOURCES OF ERROR
----------------
Errors detected by the program present the user with the choice either to continue ("OK") or to stop the program ("Cancel"). Basic errors give the user the single option of "Cancel" to stop the program.

The maximum size of the Draw file is given by the variable maxDrawFileLen% in the !RunImage program. If you find that this is insufficient ("File too long"), try making your Draw file simpler. If you have to increase maxDrawFileLen%, this can be done by increasing the size of the sprite, ssize% in !RunImage, since they are the same.

If a file of type other than text or Draw is dropped into Chaos, the error "Invalid file type", along with the file type, is given.

The maximum number of transformations is given by maxTrans%, currently 10; this should be plenty. If not ("Too many transformations") then increase the variable accordingly.

If the text file is not of the correct format, then the error "Improper text file format" is given; this should only occur if the text file was not created by the Chaos application.

The Draw file must contain at least two components in order to be sensible; otherwise the error "Not enough objects" is given.

The application checks the Draw file header to ensure that it was created by the Draw application; if not the error "Not proper Draw File" is given.

The Draw file should only contain several simple paths (closed or open); anything else is ignored. If a path object in the Draw file is in slightly the wrong format this causes the error "Invalid path component". If any path contains less than 3 points ("Not enough points in shape") then the Chaos application does not have enough information to work with; put a little more detail into the Draw file. This error also occurs if the components of the Drawfile are Grouped (you should Ungroup them within Draw before saving).

The application does not have enough information if the first three points of any component (including the main shape) are in a straight line ("Points in straight line"); in this case the middle point should be deleted.

REFERENCES
----------
[1]  M F Barnsley and A D Sloan, "A Better Way to Compress Images", BYTE January 1988.

[2]  A K Dewdney, Mathematical Recreations, Scientific American, May 1990.

[3]  B B Mandelbrot, "The Fractal Geometry of Nature", W H Freeman & Co, 1982.

 RISC User 1992
