Dot-Hopper
- Type
- Graphics
- Category
- Fractal orbit plotter (GRAPHICS 8)
- Author
- Douglas Skrecky
- Published in
- Antic, May 1987 (Vol. 6, No. 1)
- Year
- 1987
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, 16K RAM, Atari BASIC; disk drive only for saving and loading pictures
- Tags
- antic, fractals, graphics-8, chaos, iterated-map, cio, screen-save, atari-basic
About the program
Dot-Hopper came with a tall tale. In Antic's May 1987 article, Gerfald, a flea who once studied maths, hops across a floor covered in spilt molasses, and his formula-driven slurping leaves a fractal pattern behind. The program does the same thing with a single pixel. It applies a tiny two-line formula over and over, plots each new point on the GRAPHICS 8 screen, and the dots slowly build up into a lacy, symmetrical picture.
Douglas Skrecky was a member of the Toronto Atari Federation user group, and this was his first program in Antic. The whole thing is 51 lines and runs on any 8-bit Atari. Only the save and load options need a disk.
Typing it in
Antic printed the program with TYPO II checksum codes, which the disk version doesn't have. The menu text uses inverse video: {inv}…{/inv} means press the Atari (inverse) key, type the characters, then press it again. Line 190 has {BELL}{UP}{DEL LINE}. To type these, press ESC then CTRL-2 for the bell, ESC then CTRL-minus for cursor up, and ESC then SHIFT-DELETE for delete line.
Two lines hide machine code, so take care with them. In line 330 the string in ADR("hhh{inv}*{/inv}LV{inv}d{/inv}") is a 6502 routine: three PLAs, TAX, then JMP $E456, the operating system's CIO entry point. The {inv}*{/inv} and {inv}d{/inv} must be inverse. In the PRINT #1 on the same line, {CTRL-,} is CTRL-comma, the heart character (code 0).
How to use it
Press C to create a picture. You'll be asked for the left, right and top borders of the area to view, then for three formula constants, CY, MX and CX. The program works out the bottom border itself, so the picture keeps the screen's 320×192 proportions. The menu suggests two sets of values to start with:
-1.5, 1.5, -1, -.2, .2, .2-15, 16, -12, -1.1, .9, -1
Press a key and the full-screen GRAPHICS 8 display appears and starts filling with dots. The space bar turns the display off, which makes the program about 30% faster. Press it again to see the progress. S saves the picture to disk and ESC returns to the menu, where L loads a saved picture. The article noted that the Antic disk included a sample picture, PIC1.
The printed article described the inputs as a scale, an X/Y origin and three constants A, B and C. The disk version asks for borders instead, but the idea is the same.
How it works
All the maths is in line 40:
XX=Y+SGN(X)*(MX*X-CX) : Y=CY-X : X=XX
This is an iterated map. Each point is computed from the last one. Even though the formula is just multiplications and a sign test, the sequence of points never settles down. Instead it traces out an intricate shape that depends on the three constants. Line 30 plots a point only if it falls inside the chosen window, so you can zoom in on a detail by giving smaller borders. Skrecky put this loop at the very top of the program because Atari BASIC finds low line numbers faster. He also suggested changing the formula itself, but warned that SQR, SIN, EXP and ^ slow it down a lot. Write 1/(1+X*X) rather than 1/(1+X^2).
The keyboard is read directly from location 764 (CH), which holds the code of the last key pressed, so checking it doesn't stop the drawing. The screen switch pokes the DMA control register SDMCTL (559) between 34 and 0. With the display off, ANTIC stops reading memory and the 6502 gets more time.
Saving and loading make a single CIO call. The program pokes IOCB #1's command byte (850), the screen address from 88/89 as the buffer (852/853), and a length of 30×256 = 7,680 bytes (856/857), the whole GRAPHICS 8 screen. Then the six-byte USR routine jumps into CIO. That's much faster than PRINTing or PLOTting the picture byte by byte.
Variations to try
- Swap
SGN(X)*(MX*X-CX)forSGN(X)*SQR(ABS(MX*X-CX)). That's slower, but gives a completely different family of shapes. - Zoom in: run the second parameter set, note an interesting area, then create it again with narrower borders around that spot. Because points outside the window are only skipped, not lost, the orbit stays the same and only the magnification changes.
Listing
2 REM HOPPER (ATARI VERSION)
4 REM BY DOUGLAS SKRECKY
6 REM (c) 1987 ANTIC PUBLISHING
10 GOSUB 600:REM INITIALIZATION
20 TRAP 20:GOSUB 100
30 IF X>LEFT AND X<RIGHT AND Y>TOP AND Y<BOTTOM THEN PLOT SCALE*(X-LEFT),SCALE*(Y-TOP)
40 XX=Y+SGN(X)*(MX*X-CX):Y=CY-X:X=XX:IF PEEK(CH)=CLEAR THEN 30
50 IF PEEK(CH)=SKEY THEN GOSUB 300
60 IF PEEK(CH)=SPACEBAR THEN GOSUB 500
70 IF PEEK(CH)<>ESCAPE THEN POKE CH,CLEAR:GOTO 30
80 GOTO 20
100 REM MAIN MENU
110 GRAPHICS 0:POKE 710,128:? "{inv} MENU {/inv}"
120 IF SCALE<>0 THEN ? " PARAMETERS USED ARE: ";NAME$:? " ";LEFT;",";RIGHT;",";TOP;",";CY;",";MX;",";CX
130 ? :? " Press {inv} L {/inv} to {inv}L{/inv}oad fractal picture":? :? " Press {inv} C {/inv} to {inv}C{/inv}reate fractal picture"
140 POKE 752,1:? :? :? " (Press {inv}ESCAPE{/inv} to return to MENU)":POKE 752,0:SCALE=0
150 IF PEEK(CH)=LKEY THEN GOSUB 400:FOR X=1 TO 1000:NEXT X:GOTO 100
160 IF PEEK(CH)<>CKEY THEN 150
170 ? "{CLEAR} {inv} CREATE A FRACTAL IMAGE {/inv}"
175 ? :? " Try Parameters:":? " :-1.5,1.5,-1,-.2,.2,.2":? " :-15,16,-12,-1.1,.9,-1"
180 POKE CH,CLEAR:? :? " LEFT BORDER =";:INPUT LEFT
190 ? " RIGHT BORDER =";:INPUT RIGHT:IF RIGHT<=LEFT THEN ? "{BELL}{UP}{DEL LINE}";:GOTO 190
200 ? " TOP BORDER =";:INPUT TOP:BOTTOM=TOP+(RIGHT-LEFT)*191/319:? " BOTTOM BORDER=";BOTTOM
210 ? " CY =";:INPUT CY:? " MX =";:INPUT MX:? " CX =";:INPUT CX:X=0:Y=0
220 SCALE=319/(RIGHT-LEFT):? :? "Press {inv}SPACEBAR{/inv} to turn screen on/off":? :POKE 752,1
230 ? :? " Press {inv} S {/inv} To {inv}S{/inv}ave Image To Disk":? :? :? :? " Press any key to continue"
231 ? "or ESC to return to Main Menu."
232 POKE CH,CLEAR
233 IF PEEK(CH)=28 THEN 100
234 IF PEEK(CH)=CLEAR THEN 233
240 GRAPHICS 8+16:POKE 710,0:COLOR 1:POKE CH,CLEAR:RETURN
300 REM SCREEN SAVE ROUTINE
302 POKE CH,CLEAR:GRAPHICS 8+32:POKE 710,0
303 ? "SAVE filename";:IO=8
304 INPUT NAME$:GOSUB 640:GRAPHICS 8+8*IO-16:POKE 710,0
310 CLOSE #1:OPEN #1,IO,0,FILENAME$
320 POKE 850,IO+3:POKE 852,PEEK(88):POKE 853,PEEK(89):POKE 856,0:POKE 857,30
330 D=USR(ADR("hhh{inv}*{/inv}LV{inv}d{/inv}"),16):IF IO=8 THEN ? #1;"{CTRL-,}({inv}J{/inv}{CTRL-,}";
340 CLOSE #1:RETURN
400 REM SCREEN LOAD ROUTINE
410 POKE CH,CLEAR:? :? "File to Load";:IO=4:GOTO 304
500 REM TOGGLE SCREEN ON/OFF
510 IF PEEK(SDMCTL)=34 THEN POKE SDMCTL,0:RETURN
520 POKE SDMCTL,34:RETURN
600 REM INITIALIZATION
610 DIM NAME$(19),FILENAME$(19):FILENAME$="D1:":SDMCTL=559
630 CH=764:ESCAPE=28:CLEAR=255:SPACEBAR=33:SKEY=62:LKEY=0:CKEY=18:RETURN
640 IF LEN(NAME$)<3 THEN NAME$(LEN(NAME$)+1)=" "
650 IF NAME$(1,1)="D" AND (NAME$(2,2)=":" OR NAME$(3,3)=":") THEN FILENAME$=NAME$:GOTO 660
660 FILENAME$(4)=NAME$
670 RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: HOP.BAS.
Credits
- Program listing: Dot-Hopper — program listing (Antic, May 1987 (Vol. 6, No. 1)) — Douglas Skrecky
- Picture: Dot-Hopper running the menu's second parameter set (-15, 16, -12, -1.1, .9, -1) after about a minute. — Douglas Skrecky (program); screenshot by the site
- Antic, May 1987 - Vol. 6 No. 1 — article: graphics demo by Douglas Skrecky — Douglas Skrecky, 1987
- Antic Software Archive — May 1987 - Vol. 6 No. 1 disk: HOP.BAS — AtariMagazines.com (Kevin Savetz), 1987
