
Graphics on the ARM
Another RISCWorld exclusive serialisation.
Mathematical and Abstract Graphics
There remains an area of computer graphics that does not belong properly in either vector graphics or pixel graphics. This is the highly specialised but fascinating field of graphics generated using a mathematical process or algorithm. Probably the best known of these is the Mandelbrot set which has received much attention in computer media. Similar in some respects are the Julia set and Lyapunov Space. All create images of engaging but somewhat unearthly beauty.
The basis of most of these images is the fractal. The essential idea of fractals is a very simple one.
Perhaps a fern leaf provides the most familiar example. Many ferns have leaves whose edges, instead of following a gentle curve around the periphery, are deeply divided into lobes which botanists call pinnae. A leaf thus divided is said to be pinnate. Often, however, the edges of the pinnae are themselves similarly divided, so that there are two distinct levels of division and the leaf is then said to be bipinnate. And in some examples even the edges of these second divisions are further subdivided, making the leaf tripinnate. If you examine a pinna from a tripinnate leaf under magnification, it may look remarkably like the whole leaf seen without magnification. And that is significant since the characteristic property of a fractal pattern is that it tends to look the same irrespective of the magnification factor with which it is examined. There are always further levels of detail too small to see. Indeed there is in theory no end to the detail contained in the pattern.
The Mandelbrot set
Without introducing complex mathematics which you have no real need to understand, suffice it to say that the Mandelbrot set is similar to an infinitely pinnate fern leaf that has been turned inside out. It is a geometrical figure having a number of levels or contours of ever increasing complexity enclosing a central void. Ideally the number of levels is infinity, but since our computers are finite we are obliged as ever to make a compromise, so let's make the number of levels 256. This is a convenient number, since in a 256colour mode we can assign each level its own colour and thereby ensure that (theoretically) the resulting graphic uses every colour in the palette.
The following description is of necessity a gross simplification. The first level in the set is a filled circle, i.e. it is the simplest possible curved shape, having a single radius. Inside this we draw the second level, a slightly more complex shape, an oval, which has two radii. Inside this we draw the third level, slightly more complex stilla pear shapehaving 4 radii. Each successive level has twice as many twists in its contour as the previous and each hugs the contour of the previous a little more closely. This continues until, in our example, the 256th level.
Although the first few levels hardly inspire great interest, by the fifth and sixth levels interesting shapes begin to emerge in the overall graphic. Some 'wobbles' in earlier levels become exaggerated in successive levels leading eventually to near circular bays or sharp promontories. Indeed the whole figure resembles a contour map of fabulous mountains surrounding an inland sea whose coastline is a maze of inlets and natural harbours. As you examine successively deeper levels, the coastline becomes more and more detailed and its fractal nature becomes ever more apparent: zooming in on one of the nearcircular bays will reveal that its edges are not as smooth as they appeared at lower magnification, they themselves have inlets and smaller near circular harbours.
Mandlbrot
There have been many Mandelbrot generators for the ARM Machines, especially in the public domain and shareware market. But one of the finest applicationsavailable from Tekoa Graphics and not in the public domain is simply called Mandlbrot and it comes from Raymond Keefe, originator of Art20 described in Chapter 9. Like Art20, Mandlbrot will run in any desktop screen mode, but obviously the most attractive graphics are obtained in the 256colour modes. You really need a machine having at least 2 Mbytes of RAM,
Although not as fast as some Mandelbrot generators, it is a very flexible program. Any number of levels can be set with a wide choice of ways in which colours can be assigned to levelsthe colours can even be changed after the set has been plotted. But one word of warning: the time taken to plot the Mandelbrot increases dramatically as you add more levels and probe deeper into the set. Even with an ARM3 the third picture in plate 11, which magnifies an area of a 256level Mandelbrot by about 100, took about an hour.
Clicking SELECT on the application icon or on Create New Mandelbrot from the icon bar menu leads to a dialogue box in which you enter the required screen mode. The Mandelbrots produced occupy full screens in the selected mode.
When you have entered your choice of screen mode, you are taken into a sprite window (Figure 15.2) which is of course initially empty. Its menu allows you to save the sprite (you would of course only choose this option later on when there is something worth saving) or the Mandelbrot (.i.e. all the settings and calculations so you can resume an exploration that was previously interrupted). To start a new Mandelbrot you must select the Draw Mandelbrot option and this takes you into the main window which, in order to provide the largest possible graphics area, occupies the whole screen (Figure 15.3). You can return to the desktop environment by selecting the last option, Desktop, from this screen's menu. Any other applications that were running will be intact.
In fact Mandelbrot drawing does not begin when you enter the main window. It only begins when you select Draw from the main menu. But first you will probably wish to select a few options such as the number of levels and the colour system. The number of levels need not be the same as the number of colours. If you have more levels than colours (e.g. 32 levels in a 16colour mode) each colour will be used twice. And if you have more colours than levels, not all colours will be used. You can even change your colour regime after the Mandelbrot has been drawn and the screen will be updated to reflect your decision. Usually each palette colour is used in turn. You can reverse the colour sequence or introduce an offset so that the sequence starts on a different colour.
Two provisions are made for magnification. The simplest is to drag a box anywhere in the drawing. It will be constrained to screen proportions. Thereafter clicking Select will redraw the area enclosed by the box at full screen size. This involves more calculation than the original screen and will therefore take longer to draw. Alternatively you can enter the coordinate of the bottom left hand corner of the area of interest together with the width of the area. There is an option to display pointer coordinates permanently, so you can quickly find the values for any areas of interest. You can return to the previous view using the Undo option. The Rough option provides a rapid drawing of the requested area at V64 of full screen size and much faster than a full draw; this is useful for checking that you have selected the right area before waiting for it to be drawn in detail. The Faster option (selected by default) provides more rapid drawing, but the calculations are not quite so accurate.
Any screen of interest can be saved as a standard RISC OS sprite and this of course can be loaded into Paint, Art20 or any other application that accepts sprite files. You can also save the whole Mandelbrot complete with settings and calculations in order to resume a session that must be interrupted. If you are interested in this kind of graphic, then Mandlbrot will occupy you and your machine for many happy hours.
Lyapunov
Also from Raymond Keefe and available from Tekoa Graphics is an application entitled Lyapunov which creates images in Lyapunov Space. Indeed they look just like something that you might expect to see in outer space. For further information on the work of Aleksander Lyapunov see the article 'Leaping into Lyapunov Space' in Scientific American, September 1991.
The program itself works in almost exactly the same way as Mandlbrot. The formula that creates the images, however, is different and one of the differences is that it requires a seed value. Whereas there is only one Mandelbrot set whose only possible variations are in number of levels and colours assigned to levels, mere are limitless possible Lyapunov images. You can make four settings: the Seed value allows you to enter a value that will be used in calculations; Settling allows you to enter how many iterations (repeated calculations) of the formula are undertaken before any averaging is done, its purpose is to allow the formula to 'settle down' before its results are used; Iterations determines how many iterations of the formula are averaged; Sequence determines the sequence in which x and y values are entered into the formula. These four variable inputs, then, allow considerable variation of the images produced.
Colour control is much as for Mandlbrot and the Autoscale setting is recommended as it works out a spread of colours to cover the values obtained. Chaotic regions, however, are always shown dark. It is another application offering endless fascination to those with a taste for the abstract.
Third Millennium
Third Millennium is a public domain library maintained by Jean van Mourik which specialises in the kind of abstract and mathematical graphics described in this chapter. Also available are various dithering techniques to extend the colours available from regular modes.
Besides software, Jean sells postcards and tshirts depicting his graphics creations, a video of fractal based graphics backed with ambient music and he is working on a book containing a collection of his graphics.
If you enjoy abstract graphics of this kind you can do no better than purchase the Third Millennium's latest Rainbow Demo disc which is packed with graphics, some animated. guaranteeing you a colourful tune, Many of the graphics are created and animated by simple BASIC programs which you can list and adapt to suit your own purposes.
Among the most fascinating of his creations are cellular automata. These are patterns based on cells which undergo transformations and multiplications which in some ways recall the growth of populations of microorganisms. Each cell is evaluated in turn on the basis of its proximity to other cells and the screen replotted with new values for each cell. The Game of Life (not itself on the Rainbow Demo disc) is an example of a cellular automaton that has enjoyed occasional bursts of popularity.
Other examples are the twodimensional transformations such as Whirl (plate 15) which uses the short BASIC program in Listing 15.1. When the screen has been plotted (which takes some time) it is animated by the simple expedient of changing the colours on a cyclical basis.
Listing 15.1 A twodimensional transformation
10 REM >WHIRL1
20 REM JERH VAN MOURIK, THIRD MILLENNIUM 4 PANTLLYN,
25 REM LLANDYBIE, AMMANFORD, DYFED, U.K. SA18 3JT
30 F=9999:MODE20:ORIGIN640,512:OFF
35 REM INPUT "AMOUNT OF SKEW (SUGGEST 9999)";F
40 DIMR%(15):DIMG%;(i5):DIMB%(15):DIMD%(i5):DIMC%(5)
45 FOR X=9T015:READ C,D,E:COLOUR X,C,D,E:R%(X)=C:G%(X)=C:B%(X)=C:NEXT
50 FORX%=511 TO 512 STEP 2:D%=X%*X%:A=1:FORY%=639 TO 640 STEP 2
55 S=F/SQR(D%=Y%*Y%):A=SQRS:P%=X%*COSA+Y%*SINA+1244
56 IF P%>1234:GCOL(P% MOD 15)+1:POINTY%,X%:POINTY%X%:NEXT:NEXT:GOTO90
60 NEXTiNEXT
70 TIME=0:REPEAT:R%=R%(1):G%=G%(1):B%=B%(1)
71 FOR X%=2TO15:R%(X%1)=R%(X%):G%(X%1)=G%(X%):B%(X%1)=B%(X%):NEXT
72 R%(15)=R%:G%(15)=G%:B%(15)=B%:WAIT
73 FORX%=1 TO 15:COLOUR X%,R%(X%),G%(X%),B%(X%):NEXT:UNTIL 0
80 DATA 0,0,0,192,0,240,144,48,240,96,96,240,48,144,240,0,192,240
81 DATA 0,240,192,48,240,144,96,240,96,144,240,48,192,240,0,240
82 DATA 192,0,240,144,48,240,96,96,240,48,144,240,0,192
93 REM R,G,B VALUE OF THE PALETTE
90 REM TO SAVE THE IMAGE DELETE "REM" FROM THE FOLLOWING LINE
100 REM *SCREENSAVE IMAGE1
Fortran Friends
Fortran is a programming language ideally suited to mathematical and scientific work. On the ARM machines C, Assembler and BASIC reign supreme and little is heard of Fortran, but there is an active user group called Fortran Friends (address in Appendix 5). They have compiled a disc of graphics software which is now available as Shareware Disc 44 from Norwich Computer Services (address in Appendix 5).
SphereRot is an example of sprite manipulation; it creates a sprite showing spherical objects of various sizes arranged in different waysagain the threedimensional effect is most attractive. WimpPoly draws a large selection of threedimensional polyhedra which can be saved as Draw files.
RISCWorld
