(C)opyright 1987, Otto J. A. Smith. (206) 385-1956 Making Wallpaper on the Amiga Part I. Charles Dewdney popularized the term "Wallpaper for the Mind" to refer to certain kinds of automatic picture generating programs. It is fairly easy to write programs that automatically generate pictures in any of the languages available on the Amiga, including Basic, although the easiest method to generate any of the types of pictures mentioned here is with the program Doug's Math Aquarium, which is ideally suited to this kind of endeavor. Since we are dealing with the Amiga computer we will assume we have 32 color registers available for 32 simultaneous colors on the screen. By far the easiest kind of picture to create is a moire pattern. This can be done in Basic using two simple loops that calculate a color for every point on the screen. There are two separate simple problems involved in this. The first is to determine a value for x and y at each point on the screen. These values need not be the same as the pixel coordinates. The second problem is deciding on a color for each pixel based on the values of x and y. Here is an example of a formula for generating a color from x and y: COLOR = (X*X + Y*Y) MOD 32 This formula generates a moire pattern of overlapping and interwoven circles. Any formula can be used, provided it is scaled to values that can be represented as color registers. If the numbers are big enough we can take them modulo 32 to assign each number at each pixel to a color register. Here is an outline for a very specific simplistic program that will generate only one picture: 1. Allocate a low-res screen with 5 bit-planes. 2. For X = 0 to 319 and For Y = 0 to 199 do the following: Calculate the value of COLOR = (X*X + Y*Y) MOD 32 Assign the pixel at X,Y to the color register COLOR. Repeat until loops are exhausted. 3. Assign colors or whatever to wrap up the program and exit. This may not be prove to be the most exciting picture you could hope to generate. To change this picture you can do several things. You could change the color scheme. You may be suprised at how different this picture will look with different color schemes. The apparent sizes of the overlapping circles can be made to change by changing the color scheme. To change the picture you could also change the formula for the color. (keep the MOD 32) For instance COLOR = ((X+Y)/(X-Y)) MOD 32, or COLOR = (X+X/Y+Y) MOD 32. It would also be nice to be able to change the values of and x and y in the two loops to some other set of numbers rather than 0 to 319 and 0 to 199. One way of doing this would be to insert two lines of code in the inner loop that calculate a new value for x and y. For instance: FOR X = 0 to 319 FOR Y = 0 to 199 NEWX = X/7.15 NEWY = Y/7.15 COLOR = (NEWX * NEWX + NEWY * NEWY) MOD 32 REM PLOT THE PIXEL X,Y WITH COLOR REGISTER COLOR HERE. NEXT Y NEXT X The values of X and Y bear a relationship to points in a plane. The above solution would be more attractive if it preserved this relationship. To make this work, we need numbers that define where we are in the real plane. Let us define values for XMAX, XMIN, YMAX and YMIN. These values define the corners of a rectangle that looks like the illustration below. XMIN,YMIN XMAX,YMIN _______________ . . . . . . . . . . . . --------------- XMIN,YMAX XMAX,YMAX We would like the CRT screen to correspond to this rectangle. To make this the case, we can calculate NEWX and NEWY as follows: NEWX = XMIN + ((XMAX-XMIN)/319) * X NEWY = YMIN + ((YMAX-YMIN)/199) * Y And we can proceed as above. By building a program that prompts for the values of XMAX, XMIN, YMAX and YMIN we can move around on the infinite plane defined by the formulas in our program. There are many ways to make this procedure faster. In particular NEWX and NEWY calculations can be factored out of the two inner loops. This method of plotting functions of two variables is very general. The Mandelbrot set is an example of a plot done this way in which the formula is not a simple function of x and y, but is a recursive function of x and y. The program Doug's Math Aquarium is designed to make the production of these "Wallpaper for the mind"-type plots much easier. It allows the entry of a formula which it then compiles, in order to make the actual plotting step faster. It allows the user to zoom in or out of the picture using the mouse. It includes tools for scaling, setting the colors, color cycling, saving and recovering pictures in IFF format and saving and recovering formulas. Recursive formulas are allowed, so the Mandelbrot set is only one of a large number of different kinds of plots it is capable of producing. Although Doug's Math Aquarium is fast, it is possible to write special purpose programs for particular formulas, such as the Mandelbrot set, that are faster. In order to make the plot faster the programmer can use scaled integer arithmatic, he can write in machine language and he can use special features of the particular formula he is writing for, such as range checking. Some but not all of these techniques can be included in the formulas in Doug's Math Aquarium, because Doug's Math Aquarium does all calculations in Fast Floating Point Arithmatic.