Fractal Zoom
- Type
- Graphics
- Category
- Fractal (Mandelbrot/Julia) plotter with zoom
- Author
- Charles Jackson
- Published in
- Antic, April 1986 (Vol. 4, No. 12)
- Year
- 1986
- Language
- Atari BASIC
- Requirements
- Atari BASIC, disk drive (62 sectors per picture plus up to 246 for a scratch file), joystick in port 1; GTIA for modes 9–11; XL/XE for mode 15; 130XE RAMdisk optional
- Tags
- antic, fractals, mandelbrot-set, julia-set, complex-numbers, mathematics, gtia, graphics-8, graphics-15, zoom, disk, 1986
About the program
In 1986 fractals were the talk of computer graphics, helped by Lucasfilm's Rescue on Fractalus! and Koronis Rift. Antic's April issue explained them from the ground up: the coastline of Britain, the Hausdorff dimension, and the complex numbers behind the Julia curves first studied by Gaston Julia and Pierre Fatou. Then Program Editor Charles Jackson gave readers Fractal Zoom to draw them. It plots a Julia set in any of five graphics modes and then lets you zoom in on any part of it, again and again, finding ever finer filaments, and sometimes tiny copies of the whole curve.
Jackson was frank that it is "probably the most time-consuming program you'll ever run". Dull images take about 40 minutes, but the really attractive ones need 12–48 hours each. An emulator's warp mode makes this far more bearable today.
Typing it in
Lines 610, 730, 980–982 and 1630 contain special characters (machine-language and screen-control strings). {inv} … {/inv} means press the Atari (inverse) key before and after, {CTRL-x} means hold CTRL and press the key, and {CLEAR} is ESC then SHIFT-CLEAR. In the magazine, Listing 2 wrote these lines to a file called LINES.LST for you to ENTER, but it isn't on the disk. Antic printed TYPO II checksums beside each line of the magazine listing. They are not part of the program.
How to use it
RUN it and choose a mode: 8 (two colours, 61,440 points), 9, 10 or 11 (GTIA, 15,360 points), or 15 (four colours, XL/XE). Give the file names and corner values as prompted (the defaults draw the whole curve shown in the magazine). You can choose to blank the screen to save time. While it is blanked, holding START shows the picture. When the image is finished, the picture (62 sectors) and a one-sector data file are saved.
To zoom, press 1 and a frame appears at the top left. Move it with the joystick and change its size with the number keys (1 is smallest, 0 is full screen). Press the button to start drawing the framed area at full size. Jackson advised sticking to larger windows until you know a curve, because it's easy to get lost, and recommended zooming in on the hair-like filaments. 130XE owners can set RAMDSK=1 in line 55 to put the scratch file on the D8: RAMdisk.
How it works
The heart is lines 280–400. Each pixel gives a complex constant (AC, BC, worked out from the corner values and step size in lines 280–290). Z starts at 0 and is repeatedly squared, with the constant added each time. Strictly speaking, varying the constant and always starting Z at zero draws the Mandelbrot set. The article used the names loosely and called the images "Julia Fractal Curves, nicknamed the Mandelbrot Set". BASIC has no complex numbers, so each step is done in real and imaginary parts: AZ2=AZ*AZ-BZ*BZ+AC and BZ2=2*AZ*BZ+BC. If the size of Z passes 2, the point escapes. The program tests SIZE>4 on the squared value, which avoids a slow SQR. A point that survives 100 rounds is inside the curve and coloured black, and the others are coloured by how quickly they escaped (lines 1500–1550). The escape counts go into a scratch file first, so that on the second pass the colour formulas can be rescaled to the range actually found. This matters when zooming, where counts might only run from 40 to 60. In GRAPHICS 8, or when the counts already cover the full range, the second pass is skipped.
Changes from the published listing
One change, so the program also runs under Altirra BASIC, the free replacement BASIC built into many emulators. Altirra BASIC adds commands called ERR, MOVE, so it rejected the published lines that use those words as the start of a variable name. The variable is renamed everywhere in the program. The new name is the same length, so the memory layout is unchanged and the program behaves exactly as published on genuine Atari BASIC. If you type it in from the magazine, the original names work fine on a real Atari.
| Published | Now | Lines |
|---|---|---|
ERR |
ERX |
1190, 1320, 1400, 1410 |
MOVE |
MOVX |
984, 1010, 1020 |
Listing
10 REM FRACTAL ZOOM
20 REM BY CHARLES JACKSON
30 REM (c) 1985, ANTIC PUBLISHING
50 BRK=1:IF PEEK(53279)=5 THEN BRK=0
55 RAMDSK=0
60 DIM PLY1$(229),PLY2$(229),PM$(100),F$(18),P$(1),DAT$(18)
62 GOTO 70
65 POKE 77,0:IF BRK THEN POKE 16,112:POKE 53774,112
66 RETURN
70 GOSUB 65:? "{CLEAR}{inv}C{/inv}reate a New fractal":? :? "{inv}L{/inv}oad one from disk";:INPUT P$
80 IF NOT (P$="C" OR P$="L") THEN 70
90 IF P$="L" THEN 1320
100 ? "{CLEAR}MODE (8 - 11, 15)";:INPUT MODE:IF NOT ((MODE>7 AND MODE<12) OR MODE=15) THEN 100
110 GOSUB 1210:GOSUB 1280:GOSUB 1180
120 ? "{CLEAR}":POSITION 2,15:? "DEFAULTS ARE:":LIST 160,162
130 FOR X=17 TO 19:POSITION 1,X:? "{DEL CHAR}{DEL CHAR}{DEL CHAR}{DEL CHAR}":NEXT X
140 POSITION 2,2:? "ENTER ACORNER, BCORNER, SIDE"
150 TRAP 160:INPUT ACORNER,BCORNER,SIDE:GOTO 170
160 ACORNER=-2
161 BCORNER=-1.145288
162 SIDE=0.253866
170 TRAP OUT
180 IF MODE=15 THEN GOSUB 600
190 IF MODE=8 THEN GRAPHICS 8+16:POKE 710,0
200 IF MODE=9 THEN GRAPHICS 9
210 IF MODE=11 THEN GRAPHICS 11
220 IF MODE=10 THEN GRAPHICS 10:FOR X=0 TO 8:POKE 704+X,18*X:NEXT X
230 GOSUB 65:GOSUB 1600
250 UP=1/2.1:COLFACT=(COL-1)/(MAXITER^UP)
255 OPEN #2,8,0,DAT$:SCR=PEEK(88)+PEEK(89)*256
260 FOR N=0 TO HEIGHT
270 FOR M=0 TO LNGTH
280 BC=N*GAPH+BCORNER
290 AC=M*GAPL+ACORNER
300 AZ=0:BZ=0
310 COUNT=1:POKE 77,0
320 AZ2=(AZ*AZ)-(BZ*BZ)+AC
330 BZ2=2*AZ*BZ+BC
340 AZ=AZ2:BZ=BZ2
350 SIZE=AZ2*AZ2+BZ2*BZ2
360 IF SDMCTL THEN POKE 559,0:IF PEEK(53279)=6 THEN POKE 559,34
370 IF BRK THEN POKE 16,112:POKE 53774,112
380 IF PEEK(53279)=2 OR PEEK(53279)=3 THEN IOCTL=8:POP :POP :GOTO 480
390 IF SIZE>4 THEN 410
400 COUNT=COUNT+1:IF COUNT<=MAXITER THEN 320
410 GOSUB 1500
420 IF MODE=15 THEN GOSUB 1660:GOTO 451
450 PLOT M,N
451 IF MODE<>8 THEN PUT #2,COUNT
454 IF COUNT>MAXCNT THEN MAXCNT=COUNT
456 IF COUNT<MINCNT THEN MINCNT=COUNT
460 NEXT M
470 NEXT N
480 CLOSE #2:MF=100/(MAXCNT-MINCNT):BF=1-MF*MINCNT
490 POKE 559,34:SKIP=0
492 COUNT=MAXCNT:GOSUB 1500:KLR1=KLR:COUNT=101:GOSUB 1500:SKIP=(KLR1=KLR)
493 COUNT=MINCNT:GOSUB 1500:KLR1=KLR:COUNT=1:GOSUB 1500
500 TRAP OUT:CLOSE #1:IF ((SKIP AND (KLR1=KLR)) OR (MODE=8)) THEN 509
501 OPEN #1,4,0,DAT$
502 FOR N=0 TO HEIGHT:FOR M=0 TO LNGTH:GET #1,A:POKE 77,0
503 COUNT=INT(MF*A+BF+0.5):GOSUB 1500
504 IF MODE=15 THEN GOSUB 1660:GOTO 506
505 PLOT M,N
506 IF SDMCTL THEN POKE 559,0:IF PEEK(53279)=6 THEN POKE 559,34
507 GOSUB 65
508 NEXT M:NEXT N
509 IOCTL=8:GOSUB 650
510 IF RAMDSK THEN DAT$(2,2)=STR$(DRV)
514 CLOSE #1:OPEN #1,8,0,DAT$
515 ? #1;MODE:? #1;ACORNER:? #1;BCORNER:? #1;SIDE:CLOSE #1
520 GRAPHICS 0:POKE 752,1
530 ? F$;" IS DONE":? :? "Press {inv} START {/inv} to continue."
540 IF PEEK(53279)<>6 THEN 540
550 IOCTL=4:IF MODE=15 THEN GOSUB 600:GOSUB 650:GOTO 690
560 IF MODE=8 THEN GRAPHICS 8+16:POKE 710,0:GOSUB 650:GOTO 690
570 IF MODE=9 THEN GRAPHICS 9:GOSUB 650:GOTO 690
580 IF MODE=11 THEN GRAPHICS 11:GOSUB 650:GOTO 690
590 IF MODE=10 THEN GRAPHICS 10:FOR X=0 TO 8:POKE 704+X,18*X:NEXT X:GOSUB 650:GOTO 690
600 GRAPHICS 8+16
610 JNK=USR(ADR("h{inv}-{/inv}0{CTRL-B}{inv}{CTRL-E}P-{/inv}1{CTRL-B}{inv}{CTRL-E}Q {/inv}{CTRL-C}{inv}){/inv}N{inv}{CTRL-Q}P {/inv}{CTRL-F}{inv}1PI{/inv}{CTRL-O}{inv}P{/inv}{CTRL-D}{inv}){/inv}{CTRL-N}{inv}{CTRL-Q}PI{/inv}O{inv}P{/inv}{CTRL-D}{inv}){/inv}N{inv}{CTRL-Q}PH@M{CTRL-P}i){/inv}{CTRL-G}{inv}{CTRL-E}{/inv}W{CTRL-.}"))
640 POKE 710,0:POKE 709,148:POKE 708,52:POKE 712,196:RETURN
650 CLOSE #1:OPEN #1,IOCTL,0,F$
660 IO=848:POKE IO+2,IOCTL+3:POKE IO+4,PEEK(88):POKE IO+5,PEEK(89):POKE IO+8,0:POKE IO+9,30
670 JNK=USR(ADR("hhh{inv}*{/inv}LV{inv}d{/inv}"),16):CLOSE #1
680 RETURN
690 X=XZ:Y=XZ
700 POKE 559,46:POKE 764,255
710 PMBASE=124:POKE 54279,PMBASE:PMB=PMBASE*256
720 POKE 559,46:POKE 53277,3
730 JNK=USR(ADR("h{inv}-{/inv}o{CTRL-B}{CTRL-I}{CTRL-A}{inv}{CTRL-M}{/inv}o{CTRL-B}{CTRL-.}")):REM SETS BIT 1 OF GPRIOR
740 PX1=47:PX0=211:HITE=97:DIST=77:ZOOM=1
750 ST=STICK(XZ):IF PEEK(764)=255 THEN 870
760 IF PEEK(764)=50 THEN HITE=97:DIST=77:ZOOM=1
770 IF PEEK(764)=48 THEN HITE=88:DIST=70:ZOOM=0.9091
780 IF PEEK(764)=53 THEN HITE=78:DIST=62:ZOOM=0.8051
790 IF PEEK(764)=51 THEN HITE=72:DIST=57:ZOOM=0.7415
800 IF PEEK(764)=27 THEN HITE=59:DIST=47:ZOOM=0.6415
810 IF PEEK(764)=29 THEN HITE=54:DIST=43:ZOOM=0.5585
820 IF PEEK(764)=24 THEN HITE=44:DIST=35:ZOOM=0.4546
830 IF PEEK(764)=26 THEN HITE=34:DIST=27:ZOOM=0.351
840 IF PEEK(764)=30 THEN HITE=29:DIST=23:ZOOM=0.299
850 IF PEEK(764)=31 THEN HITE=19:DIST=15:ZOOM=0.196
860 POKE 764,255
870 PX0=2*DIST+PX1
880 IF Y+HITE>97 THEN Y=97-HITE
890 IF NOT (PEEK(644)) THEN 1110
900 IF (Y>0) AND (ST=10 OR ST=14 OR ST=6) THEN Y=Y-C1
910 IF (Y+HITE<97) AND (ST=13 OR ST=9 OR ST=5) THEN Y=Y+C1
920 IF PX1>47 AND ST>8 AND ST<12 THEN X=X-1:PX1=PX1-1:PX0=PX0-1
930 IF (PX0<201) AND (ST>4 AND ST<8) THEN X=X+1:PX1=PX1+1:PX0=PX0+1
940 IF Y<XZ THEN Y=XZ
950 PY1=15+Y
960 IF HITE+PY1>111 THEN PY1=112-HITE
970 IF PX0>201 THEN PX1=201-2*DIST:PX0=201
980 PM$(1,50)="{inv}X{/inv}hhh{inv}{CTRL-E}U{/inv}h{CTRL-X}i{CTRL-B}{inv}{CTRL-E}N{/inv}h{inv}{CTRL-E}M{/inv}h{inv}{CTRL-E}L{/inv}h{inv}{CTRL-E}K{/inv}hh{inv}{CTRL-E}P{/inv}hh{inv}{CTRL-E}Q{/inv}hh{CTRL-X}e{inv}Q{CTRL-E}O&Up{/inv}{CTRL-P}{inv}%M{/inv}{CTRL-X}i{inv}{CTRL-,}{CTRL-E}M%N{/inv}i"
982 PM$(51,100)="{CTRL-,}{inv}{CTRL-E}NJPp {/inv}{CTRL-,}{inv}"{/inv}{CTRL-,}{inv}DQ{CTRL-P}{/inv}{CTRL-S}{inv}DO0{/inv}{CTRL-O}{inv}{CTRL-D}T{CTRL-J}(1K$T{CTRL-Q}Mh){/inv}{CTRL-,}{inv}p{/inv}{CTRL-D}{inv}){/inv}{CTRL-,}{inv}{CTRL-Q}MH@{CTRL-,}P{CTRL-.}&U%P{/inv}{INS LINE}{CTRL-,}{inv}P{/inv}{CTRL-.}"
984 MOVX=ADR(PM$)
990 IF MODE=8 THEN POKE 704,14:POKE 705,14
1000 GOSUB 1040
1010 JNK=USR(MOVX,XZ,PMB,ADR(PLY1$),PX0,PY1,LEN(PLY1$))
1020 JNK=USR(MOVX,C1,PMB,ADR(PLY2$),PX1,PY1,LEN(PLY2$))
1030 GOTO 750
1040 PLY1$="{CTRL-,}":PLY1$(HITE)=PLY1$:PLY1$(2)=PLY1$:PLY2$=PLY1$
1050 PLY1$(1,8)="{INS CHAR}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}"
1060 PLY1$(LEN(PLY1$)-7,LEN(PLY1$))="{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{CTRL-A}{INS CHAR}":PLY2$=PLY1$:PLY2$(1,8)="{INS CHAR}{inv}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{/inv}"
1090 PLY2$(LEN(PLY2$)-7,LEN(PLY2$))="{inv}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{CTRL-,}{/inv}{INS CHAR}":RETURN
1110 KOL=INT(MFACT*PX1+BFACT+0.5):ROW=INT(2*PY1-30+0.5)
1120 IF KOL<0 THEN KOL=0
1130 IF ROW<0 THEN ROW=0
1140 ACORNER=ACORNER+(GAPL*KOL)
1150 BCORNER=BCORNER+(GAPH*ROW)
1160 SIDE=SIDE*ZOOM
1170 POKE 53248,1:POKE 53249,1:GOSUB 1180:GOTO 170
1180 GRAPHICS 0:? "SAVE filename";:INPUT PLY1$:IOCTL=8
1190 GOSUB 1380:IF ERX THEN 1180
1195 DAT$=F$:DAT$(LEN(F$)+1)=".DAT"
1200 RETURN
1210 MAXITER=100:HEIGHT=191:LNGTH=159:COL=4:C1=1:X2=255:XZ=0:IO=848:OUT=40000
1220 MFACT=0.501275368:BFACT=-24.0612177
1230 IF MODE=8 THEN HEIGHT=191:LNGTH=319:COL=2
1240 IF MODE=10 THEN HEIGHT=191:LNGTH=79:COL=9
1250 IF (MODE=9) OR (MODE=11) THEN HEIGHT=191:LNGTH=79:COL=16
1260 IF MODE=8 OR MODE=15 THEN MFACT=MFACT*4:BFACT=BFACT*4
1270 RETURN
1280 ? "{CLEAR}SCREEN ON (Y/N)";:INPUT P$
1290 IF NOT (P$="Y" OR P$="N") THEN 1280
1300 SDMCTL=(P$="N"):RETURN
1320 ? "{CLEAR}File to Load";:INPUT PLY1$:GOSUB 1380:IF ERX THEN 1320
1330 PLY1$=F$:PLY1$(LEN(F$)+1)=".DAT"
1340 TRAP 1320:CLOSE #1:OPEN #1,4,0,PLY1$
1350 INPUT #1,MODE:INPUT #1,ACORNER:INPUT #1,BCORNER:INPUT #1,SIDE:CLOSE #1
1360 GOSUB 1210:GOSUB 1280:GOSUB 1600
1370 TRAP OUT:? :? "Press {inv} START {/inv} to begin":GOTO 540
1380 IF LEN(PLY1$)<3 THEN 1390
1382 IF PLY1$(1,1)="D" AND PLY1$(3,3)=":" THEN F$=PLY1$:GOTO 1400
1385 IF PLY1$(1,2)="D:" THEN PLY1$=PLY1$(3)
1390 F$="D1:":F$(4)=PLY1$
1400 ERX=0:FOR X=1 TO LEN(F$):IF F$(X,X)="." THEN ERX=1
1410 NEXT X:IF ERX THEN ? :? "{BELL}BAD FILENAME{BELL}"
1420 DRV=VAL(F$(2,2)):RETURN
1500 IF (MODE=9) OR (MODE=11) THEN KLR=25-(INT((100/SQR(118-COUNT))+0.8))
1510 IF MODE=10 THEN KLR=17-(INT((100/SQR(139-COUNT))+0.8))
1520 IF MODE=8 THEN KLR=0:IF SIZE>4 THEN KLR=1
1530 IF MODE<>15 THEN 1550
1540 KLR=(3*(COUNT>99))+(2*(COUNT<100 AND COUNT>25))+(COUNT>2 AND COUNT<26)
1550 COLOR KLR
1560 RETURN
1600 GAPL=10*(SIDE/LNGTH)
1610 GAPH=10*(SIDE/HEIGHT)
1620 MAXCNT=0:MINCNT=MAXITER
1630 UP=1/2.1:COLFACT=(COL-1)/(MAXITER^UP)
1640 IF RAMDSK THEN DAT$(2,2)="8"
1650 RETURN
1660 X=(N*40+INT(M/4)):V=PEEK(SCR+X):FAC=USR(ADR("hhh{CTRL-X}{CTRL-J}{CTRL-J}{inv}{CTRL-E}T){/inv}{CTRL-,}{inv}{CTRL-E}U{/inv}{CTRL-.}"),V)+KLR
1670 POKE SCR+X,FAC:RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: FRACTAL.BAS.
Credits
- Program listing: Fractal Zoom — program listing (Antic, April 1986 (Vol. 4, No. 12)) — Charles Jackson
- Antic, April 1986 - Vol. 4 No. 12: scan of the printed magazine, PDF pages 10-11, 13, 16-17, 19-20 (fractal articles) — Internet Archive, 1986
- Antic disk, April 1986 - Vol. 4 No. 12: FRACTAL.BAS (detokenized listing) — Charles Jackson, 1986
