Flower Garden (The Flower Program)
- Type
- Graphics
- Category
- Mathematical line art (polar rose curves)
- Author
- Allan Moose and Marian Lorenz
- Published in
- Antic, November 1988 (Vol. 7, No. 7)
- Year
- 1988
- Language
- Atari BASIC
- Requirements
- 32K RAM with disk (24K with cassette), Atari BASIC; disk drive to save pictures; Epson-compatible printer optional
About the program
Allan Moose and Marian Lorenz were teachers on Long Island, New York, and they wrote many maths-flavoured programs for Antic, including Got-A-Minute Graphics earlier in 1988. In Flower Garden they show how a simple line-drawing routine built on one mathematical function can make surprisingly beautiful pictures.
The function is the rose equation in polar coordinates, r = R·sin(nθ). A point is given by its distance from the centre and an angle, the way a fighter pilot calls out "enemy at six o'clock, nine miles out". For a whole number n, the curve is a flower with n petals when n is odd and 2n petals when n is even. The program doesn't just trace the rose. It steps round it by a fixed angle α, drawing a straight line from each point to the next, and keeps going until it gets back to where it started. Then it shifts the starting angle by 2° and does it again. The many overlapping polygons build a lacy, symmetrical flower.
Typing it in
It's 70-odd lines of plain text. The only special characters are {CLEAR} and {BELL} (ESC then SHIFT-CLEAR, and ESC then CTRL-2), the inverse S, P and N in the menu (Atari key), and the six-character CIO call in line 810, "hhh{inv}*{/inv}LV{inv}d{/inv}". In that string the * and the final d must be inverse. DATA lines 760–780 hold a 44-byte machine-language routine for the printer dump, so check them carefully. The article calls the file FLOWERS.BAS, but on the disk it's FLOWER.BAS.
How to use it
Enter N and the step angle ALPHA in degrees. The program draws on a full GRAPHICS 8 screen and then offers a menu:
- S saves the picture as
D:PICTURE, a Micro-Painter-compatible file (the 7,680-byte screen followed by four colour-register bytes). - P prints it on an Epson-compatible printer.
- N starts a new flower.
The authors suggested some experiments. Keep N fixed and try every α from 1 to 180°. Smooth curves at small angles get lacier, fill in to a squarish centre near 90°, then "reverse" towards 180°. Try N=6, α=72, a rotating star that turns into a flower, and swapped pairs like N=200, α=20 and N=20, α=200. For loop-like figures such as N=92, α=16 or N=206, α=28, first change DELTAINC to 1 and COUNTSTOP to 360 in lines 170–180.
How it works
Lines 220–390 follow the authors' ten-step recipe. Set θ to the starting angle δ, compute r = 80·sin(Nθ), and convert to x = r·cosθ, y = r·sinθ. Then add α, compute the next point, draw a line, and repeat until θ comes back round to δ. Lines 450 and 500 keep θ and Nθ between 0 and 359 with a hand-made modulo (X-INT(X/360)*360), because Atari BASIC has no MOD operator. Multiplying x by ASPECT=320/192 stretches the picture so that it looks round on the 320×192 screen. DEG makes SIN and COS work in degrees.
The save routine writes the 7,680-byte screen in a single CIO call (the USR string jumps to CIOV), then appends the colour registers. That's the Micro-Painter format, so other paint programs can load your flowers. The printer dump uses the page-6 machine code to turn each screen column into Epson bit-image bytes.
Variations to try
- Change the 80 in lines 230 and 290 to make the flower bigger or smaller.
- Use
DELTAINC=5for a sparser flower that draws more quickly.
Listing
10 REM THE FLOWER PROGRAM
20 REM BY ALLAN MOOSE AND MARIAN LORENZ
30 REM (c)1988, ANTIC PUBLISHING
50 DIM GRAPH$(200),FN$(16)
60 ? " PLEASE WAIT..."
80 GOSUB 720
100 REM INPUT & INITIALIZATION
120 ? "{CLEAR} Enter N ":INPUT N
130 IF N=0 THEN ? "Must Be Non-Zero{BELL}{BELL}{BELL}":GOTO 120
140 ?
150 ? " Enter the incremental angle, ALPHA ":INPUT ALPHA
170 COUNT=0:DELTA=0:DELTAINC=2
180 COUNTSTOP=180:ASPECT=320/192
200 REM THE MAIN PROGRAM
210 GRAPHICS 24:POKE 710,12:POKE 712,12:POKE 709,2:COLOR 1:DEG
220 THETA=DELTA
230 R=80*SIN(N*THETA)
240 OLDX=R*COS(THETA):OLDY=R*SIN(THETA)
250 THETA=THETA+ALPHA
260 IF THETA>=360 THEN GOSUB 450
270 NTHETA=THETA*N
280 GOSUB 500
290 R=80*SIN(NTHETA)
300 XNEW=R*COS(THETA):YNEW=R*SIN(THETA)
310 PLOT ASPECT*OLDX+160,90-OLDY
320 DRAWTO ASPECT*XNEW+160,90-YNEW
330 COUNT=COUNT+1
340 IF THETA=DELTA THEN 370
350 OLDX=XNEW:OLDY=YNEW
360 GOTO 250
370 IF COUNT>=COUNTSTOP THEN 550
380 DELTA=DELTA+DELTAINC
390 GOTO 220
400 REM THE SUBROUTINES
410 REM MOD FUNCTION FOR THETA
450 THETA=THETA-(INT(THETA/360))*360
460 RETURN
480 REM MOD FUNCTION FOR NTHETA
500 NTHETA=NTHETA-(INT(NTHETA/360))*360:RETURN
530 REM THE SCREEN DUMP
550 GOSUB 1000
555 IF KEYP=35 THEN GRAPHICS 0:GOTO 120
556 IF KEYP=10 THEN 560
557 GOTO 800
560 GRAPH$(1)=CHR$(0):GRAPH$(200)=CHR$(0):GRAPH$(2)=GRAPH$
570 LPRINT CHR$(27);CHR$(65);CHR$(8)
580 SCRNMEM=PEEK(88)+PEEK(89)*256
590 MEMORY=SCRNMEM+40*191
600 HIBYTE=INT(ADR(GRAPH$)/256)
610 LOBYTE=ADR(GRAPH$)-HIBYTE*256
620 POKE 203,LOBYTE:POKE 204,HIBYTE
630 FOR COLUMN=MEMORY TO MEMORY+39
640 DUMP=USR(1536,COLUMN)
650 LPRINT CHR$(27);CHR$(75);CHR$(200);CHR$(0);GRAPH$
660 NEXT COLUMN
670 GOTO 550
690 REM M/L SCREEN DUMP ROUTINE
720 RESTORE 760
730 FOR K=0 TO 43
740 READ ML:POKE 1536+K,ML
750 NEXT K
760 DATA 104,104,141,15,6,104,141,14,6,160,4,162,192,173,0,0,202,240,24
770 DATA 145,203,200,216,173,14,6,56,233,40,141,14,6
780 DATA 144,3,76,13,6,206,15,6,76,13,6,96
790 RETURN
800 IO=848:CLOSE #1:OPEN #1,8,0,"D:PICTURE":POKE IO+2,11:POKE IO+4,PEEK(88):POKE IO+5,PEEK(89)
810 POKE IO+8,0:POKE IO+9,30:JNK=USR(ADR("hhh{inv}*{/inv}LV{inv}d{/inv}"),16)
820 PUT #1,PEEK(712):FOR X=708 TO 710:PUT #1,PEEK(X):NEXT X:CLOSE #1:GOTO 550
1000 GRAPHICS 8+32:POKE 710,12:POKE 712,12:POKE 709,2:POKE 752,1
1010 ? "{CLEAR} {inv}S{/inv}ave {inv}P{/inv}rint {inv}N{/inv}ew image"
1020 POKE 764,255
1030 KEYP=PEEK(764):IF NOT (KEYP=10 OR KEYP=62 OR KEYP=35) THEN 1030
1040 POKE 764,255
1050 GRAPHICS 8+16+32:POKE 710,12:POKE 712,12:POKE 709,2:RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: FLOWER.BAS.
Credits
- Program listing: Flower Garden (The Flower Program) — program listing (Antic, November 1988 (Vol. 7, No. 7)) — Allan Moose and Marian Lorenz
- Picture: N=6, ALPHA=72: the 'rotating star' that grows into a flower, with the Save/Print/New menu. — Allan Moose and Marian Lorenz (program); screenshot by the site
- Antic, November 1988 - Vol. 7 No. 7 — article: The Flower Program by Allan Moose And Marian Lorenz — Allan Moose and Marian Lorenz, 1988
- Antic Software Archive — November 1988 - Vol. 7 No. 7 disk: FLOWER.BAS — AtariMagazines.com (Kevin Savetz), 1988
