Classic Computer Magazine Archive START VOL. 4 NO. 7 / FEBRUARY 1990

ON DISK

CHAOS ON YOUR ST

Under All, There is Order

BY STEPHEN CLARK

"Here was one coin with two sides. Here was order, with randomness emerging, and then one step further away was randomness with its own underlying order."


--Doyne J. Farmer



Appearances can be deceiving. Find out why in the file CHAOS.ARC on Side 1 of your START disk.

In a fascinating article, Stephen Clark presents the obscure concept of chaos in clear and elegant terms. The accompanying program on your START disk was written in Mark Williams C and runs in all three resolutions.


Chaotic is the term used to describe phenomena in nature that appear to be complicated and unpredictable, but have underlying causes that are simple and easily understood. Familiar examples of chaos include a whirlpool in river rapids, smoke rising from a cigarette and the shapes of clouds. These events generally have two related properties: underlying orderand self-similarity.


Consider the Whirlpool

Order is the result of the manifestation of well-known physical laws that govern a particular event. Consider the whirlpool, for example. Its shape is determined solely by the shape of the river bottom and the rate and direction of the water flow. However, since the water flow is always changing, the shape of the whirlpool also changes. It is dynamic, chaotic.

Furthermore, it exhibits self-similarity. A close examination reveals adjacent areas of calm that are perturbed periodically by small eddies that spin off the main whirlpool. Next to these eddies are areas of calm that can be disturbed by even smaller eddies spinning away. This self-similarity at different scales exemplifies the unimportance of the region that is examined--any part looks quite like the whole.

Another example is the Mandelbrot set, which gives rise to beautiful swirling and arching patterns. Magnification of the swirls reveals tiny Mandelbrot patterns, with their own swirls and arches. Although the Mandelbrot set is incredibly complicated and unpredictable, it is obvious that it is not random.

Despite the simple and frequently small number of physical forces that affect chaotic events, they are unpredictable because these forces are interdependent and influence each other. The state of X depends on the state of Y, and vice versa. Thus, the flow of the river affects the shape of the whirlpool, and the shape of the whirlpool affects the flow of the river. Moreover, a small change in X can lead to a large change in Y. To calculate what Y will be some time in the future, we must know the exact value of both X and Y at the present. A small error in either value will soon lead to a large error in the prediction of future values.

So what appears to be random is really a result of our inability to precisely measure some set of current conditions. (The reason that weather prediction can never be accurate is because it depends on dozens, if not hundreds, of variables, none of which can be determined exactly.)


Understanding Chaos

Chaos was written as a simple but powerful illustration of the other side of the coin, the order and self-similarity that can arise from a truly random event.

Now, follow in your mind (or on paper) the process that Chaos repeats over and over. Start with three points, A, B and C, which are the vertices of an equilateral triangle. Randomly choose any vertex, say B, and then a second one, say C. Now place a point halfway between B and C, and call it D. Choose a third vertex at random--perhaps B again. Place another point, E, half way between D and B. Continue in this fashion, placing a new point halfway between the most recent point and a randomly chosen vertex.

chaos.jpg
Triangles of triangles generated by the file DEFAULT.KS.

After a while, a pattern emerges, but not just a random smear with a vague triangular outline. To see this pattern filled in with 10,000 points, run the program Chaos without changing any of the initial values. A little reflection reveals that this pattern has to be generated. How, for example, would a dot ever fall in the central area of the figure? Is this a special case, requiring that there be three vertices in the form of an equilateral triangle? What happens if one starts with four points in the form of a square, or even more points? Or what if the vertices are not evenly spaced, perhaps some of them even being coincident? And what happens if a new point is placed somewhere other than exactly halfway between a vertex and the last point? Do patterns emerge, or is the result randomness? Chaos will help you investigate.


Getting Started

To run Chaos, boot this month's START disk; the START menu program runs automatically. At the main screen, click on Prepare, then select "Chaos on Your ST." The program will un-ARC directly onto the destination drive you specify. After the program un-ARCs, click on CHAOS.PRG at the Desktop.

Chaos runs in all three resolutions. In medium resolution, each pixel changes from white to grey to black as more points fall on it. The patterns can be printed on any Epson-compatible printer and the parameters for generating the patterns can be saved and recalled from disk files. I wrote Chaos in Mark Williams C, version 3.0.6.

The program also includes a few data files as examples of the various patterns that can be created in Chaos. The files DEFAULT.KSx are the initial patterns that are first produced when the program is loaded, but these files are not required for the program to run. For fun, see if you can figure out how the other patterns were generated. (Hint: the vertices don't have to be on the periphery of the figure, nor do they have to be evenly spaced.)


THE CHAOS MENU BAR

Desktop

About Chaos...: Click here to get program information and to see the simple animation I've included.


Files

Save: Saves the parameters used to generate the pattern, but not the pattern itself, in a small ASCII file. The file extension is automatically assigned as .KS1 for low resolution, .KS2 for medium and .KS3 for high.

Load: Replaces the current setting of the parameters with those contained in a previously saved file, except for the number of iterations, which is discussed below. The file DEFAULT.KSx contains the parameters for the conditions when the program is first loaded, so the initial pattern can always be regenerated without having to restart the program.

Print: Starts a screen dump of the screen to a 9-pin Epson-compatible printer. A dialog box will present you with two choices: Fast and Accurate. The latter gives a finer dot pattern and reproduces the colors more accurately as 19 shades of grey, but is somewhat slower. The Fast option has only nine shades of grey. The printing can be aborted at any time by pressing any key.

Quit: Exits Chaos and returns you to the Desktop.


Options

Clear Screen: Clears the screen of any images and lets you start over.

No. of Vertices: Calls up a dialog box that lets you specify how many vertices your pattern will have. Click on the arrow above the digit to increase it; click on the arrow below the digit to decrease it. The maximum number of vertices is 25; the minimum is three.

Vertex Positions: Produces a grid on the screen to help you align the vertices, which are specified by moving the mouse pointer to the desired position and clicking the left button. A small star remains on the screen to indicate the vertex position. If an even number of vertices are placed at exactly the same spot, the mark will not be visible. A pair of numbers at the right of the menu bar shows how many vertices have been positioned and how many there are in total.

Distance: Lets you change the position where the next point will be placed between the last point and the random vertex. The program starts at 50 percent (halfway between the two), but you can select any value from one percent to 99 percent. Values within 10 to 15 percent of 50 percent usually give the best results, however.

No. of Iterations: Specifies the number of points to be used to produce the pattern. The default value is 10,000, which takes 21 seconds to draw in monochrome (about 500 points per second). The program takes 50 percent longer in either color resolution, extra time being required to determine the current color of a pixel and convert it to the next darker shade of grey.

Colored Points: Lets you substitute your own palette for the default Chaos grey shades, via the GEM Control Panel. This option has no effect in monochrome.

Start: Gets the program rolling. Press any key to interrupt the plotting. The proportion of points that have been plotted is shown at the right end of the menu bar.


Acknowledgments

I would like to acknowledge an episode of the PBS science series "Nova" as the inspiration for me to write Chaos. That episode discussed the phenomenon of chaos in clear and simple terms. I would also like to acknowledge the people at PBS in general and at WGBH-Boston in particular, for producing interesting and informative television shows that are well worth watching.


Stephen Clark has his Ph.D. in molecular biology and is Computer Resources Manager at the Mt. Sinai Hospital Research Institute in Toronto. He plays underwater hockey to relax. This is his first program for START.