93. Exploring fractals ~~~~~~~~~~~~~~~~~~ Fractals is an odd branch of mathematics, only discovered within the last decade or so. If you keep 'zooming in' to a plot or graph produced by a mathematical equation, you usually expect to end up with a straight line, or something equally unexciting. With Fractals, yet more detail is resolved each time you zoom in on any part of the plot. It reminds me of the witty rhyme "Great Fleas have Little Fleas, upon their backs to bite 'em, and Little Fleas have Lesser Fleas, and so ad infinitum...". In this equation, known as the Mandelbrot Set after its discoverer, the horizontal axis is effectively scaled from -2.25 on the left to +0.75 on the right, whilst the vertical axis is scaled from -1.5 at the bottom to +1.5 at the top. If you wish to examine any part of the plot in more detail, ie to 'zoom in', then just choose a narrower range of values, and edit line 10 appropriately. For example, you could use -1.5 to -1.0 instead of -2.25 to +0.75, and +0.9 to +1.4 instead of -1.5 to +1.5. Note that the second number of each pair should be more positive than the first, and that you should zoom in equally in both axes to keep the right proportions. In the first example, the total range was 3.0 for both axes, ie +0.75-(-2.25)=3.0 and +1.5-(-1.5)=3.0, whereas in the second example it was 0.5 for both axes, ie -1.0-(-1.5)=0.5 and +1.4-(+0.9)=0.5 . The plots take a very, very long time indeed, but the results are rather beautiful. The first plot may start off fairly rapidly, as it is drawing large areas of solid colour, but once it gets onto the intricate bits the speed drops dramatically, and you may even think the program has 'hung-up' if it happens to be plotting black on a black background at the time. The current plotting position is marked with a small dot, which also flashes in Mode 2. You can save the screen afterwards, to avoid having to wait all that time again, and this is done in line 110, using the filename "Screen1". To reload the display at a later date, just use the one-line program underneath. Save subsequent plots under "Screen2" etc.. If you are using cassette, you will have to suppress screen messages with *OPT1,0 before each *LOAD or *SAVE, so see page 398 of the BBC User Guide. The speed and resolution of the Beeb are barely good enough to even hint at the real detail and beauty of fractals; you need very large mainframe computers for that. (Or an Archimedes!) However, by using MODE1, or even MODE0 in line 20, more detail can be resolved at the expense of speed and colours. If you do try these modes, then alter the STEP 8 in line 40 to STEP 4 for Mode 1, and STEP 2 for Mode 0. The STEP4 in the second part of the line should not be changed. The idea for this program came from an article "Frontiers of Chaos" in The Guardian newspaper, long before all the computing magazines jumped on the bandwagon! 10 limit%=48:Xmin=-2.25:Xmax=0.75:Ymin=-1.5:Ymax=1.5 20 MODE2:VDU5 30 Horiz=(Xmax-Xmin)/1279:Vert=(Ymax-Ymin)/1023 40 FOR Xcoord%=0 TO 1280 STEP 8:FOR Ycoord%=0 TO 1024 STEP 4 45 GCOL0,11:PLOT69,Xcoord%,Ycoord% 50 M=Xmin+Xcoord%*Horiz:N=Ymin+Ycoord%*Vert:colour%=0:X=0:Y=0 60 REPEAT:R%=X*X+Y*Y:T=X*X-Y*Y+M:Y=2*X*Y+N:X=T:colour%=colour%+1 70 UNTIL R%>100 OR colour%=limit% 80 colour%=colour% MOD limit% 90 GCOL0,colour% MOD 8:PLOT69,Xcoord%,Ycoord% 100 NEXT:NEXT 110 *SAVE Screen1 FFFF3000+5000 10 REM Program to reload screen display 20 MODE2:VDU5:*LOAD Screen1 3000 (This was written in early 1985 - fractals have come on since then!)