Digital Dilithium Dahlias

Type
Graphics
Category
Plant-growth simulation (GTIA GRAPHICS 9)
Author
Leonard Buchanan (L. E. Buchanan)
Published in
Antic, March 1986 (Vol. 4, No. 11)
Year
1986
Language
Atari BASIC
Requirements
GTIA chip for GRAPHICS 9 (any XL/XE, or a later 400/800), Atari BASIC; disk or cassette
A shaded, branching plant growing up from the bottom of a GRAPHICS 9 screen, shown in pink tones on dark red because the attract mode has shifted the colours

About the program

Leonard Buchanan built computer simulations for a living. In Antic's March 1986 issue he walked readers through his usual method, using a light-hearted example. What would a flower from his wife's garden look like if it had grown on a planet made entirely of metal? The program grows the answer slowly up the screen in GRAPHICS 9's sixteen shades: a shiny, branching "Dilithium Dahlia", different every time.

Typing it in

The listing is plain Atari BASIC with no special characters. The long REMs are part of the lesson (see below), but they can be left out, except that no GOTO or GOSUB points at a REM line, so removing them is safe. Line 11 is a REM giving the author's mailing address. Antic printed TYPO II checksums beside each line of the magazine listing. They are not part of the program. The magazine pointed out that some older 400/800s lack the GTIA chip. Test with 10 GRAPHICS 9:GOTO 10: a black screen means you have it.

How to use it

RUN it and watch the plant grow from the bottom up. It takes a while. The program doesn't reset the attract-mode timer (location 77), so after several minutes without a key press the OS starts cycling the colours. Press any key and the grey metal returns. When it's finished the program sits in a loop at line 181 ("put your favorite screen dump routine here"). Press BREAK to stop. RUN it again for a new plant.

How it works: Buchanan's six steps

  1. Collect the data. He measured the real plants and turned their form into numbers. A branch appears on 14% of millimetres of height. The first branch is always a double. A branch starting within 10 mm of another stays a stub. 60% of branches grow outward at about 30°, 40% inward at about 10°, and 3% of those stop growing. The stem thins towards the top. Every plant is different but follows the same rules.
  2. Don't let the task ahead be greater than the enthusiasm behind you.
  3. Outline the program in REMs, numbered in steps of 10, before writing any code. That's why the listing reads like a plan.
  4. Write the code under each REM, plainly, straight through.
  5. See if it works. It won't, so fix it.
  6. Improve it. He deliberately left the program unpolished, inviting readers to streamline it, add a title and more colours, "and call it your own".

In the code, the program scans each row upwards and uses LOCATE to find growth points, which are drawn in colour 15 (NODE). The random tests in lines 61–115 apply the measured percentages. The subroutine at 171 gives each point its rounded, metallic look by plotting darker shades out to each side, with the width tapering as Y rises. GOTO and GOSUB targets are held in named variables (STEM, SKIP, STUB) to make the program easier to read and renumber.

Variations to try

Change the 14 in line 61 for bushier or sparser plants, alter the angles in lines 92–103, or follow Buchanan's suggestion and simulate something of your own: "Martian animals? Underwater jet planes?"

Listing

10 REM DIGITAL DILITHIUM DAHLIAS
11 REM BY L.E. BUCHANAN, BOX 733
12 REM (c) 1985, ANTIC PUBLISHING
20 REM SET EVERYTHING UP PROPERLY.
21 GRAPHICS 9
22 LMARGIN=38:X=40:RMARGIN=42
23 NODE=15:STUB=151:STEM=171:SKIP=151
30 REM MAKE THE STEM THEN MAKE THE           FIRST GROWTH NODE, WHICH IS           ALWAYS A DOUBLE BRANCH.
31 FOR Y=179 TO 159 STEP -1
32 COLOR NODE:PLOT X,Y:GOSUB STEM
33 NEXT Y
34 COLOR NODE:PLOT 38,158:PLOT 42,158
40 REM THE MAIN LOOP WHICH CREATES           THE BRANCHES AND DRAWS THE            STEMS AROUND THEM.
41 FOR Y=158 TO 20 STEP -1
42 FOR X=LMARGIN TO RMARGIN
43 COLOR NODE
50 REM LOOK AT EACH POSSIBLE DOT ON          A LINE. IF NOT A GROWTH NODE          GO ON TO THE NEXT DOT.
51 LOCATE X,Y,A:IF A<>NODE THEN GOTO SKIP
60 REM MAKE A BRANCH ONLY 14% OF             THE TIME.  OTHERWISE, JUMP            PAST THE BRANCHING ROUTINE.
61 IF RND(0)*100+1>14 THEN GOTO 131
80 REM IF IT BRANCHES UP AGAINST AN          ALREADY EXISTING BRANCH, DO           AWAY WITH IT.
81 LOCATE X+1,Y,B:IF B=NODE THEN GOTO STUB
90 REM IT HAS A 60% CHANCE OF GROW-          ING AT A 30 DEG. ANGLE OUT-           WARD FROM THE STEM......
91 CHANCE1=RND(0)*100+1
92 IF X<40 AND X-3>1 AND CHANCE1>40 THEN PLOT X-3,Y-1:FLAG=1:LMARGIN=LMARGIN-3:IF LMARGIN<1 THEN LMARGIN=1
93 IF X>40 AND X+3<78 AND CHANCE1>40 THEN PLOT X+3,Y-1:FLAG=1:RMARGIN=RMARGIN+3:IF RMARGIN>78 THEN RMARGIN=78
100 REM AND A 40% CHANCE OF GROWING           AT A 10 DEG. ANGLE BACK TO-           WARD THE STEM.....
101 CHANCE2=RND(0)*100+1
102 IF X<40 AND X+1>1 AND CHANCE2>60 THEN PLOT X+1,Y-1:FLAG=1
103 IF X>40 AND X-1<78 AND CHANCE2>60 THEN PLOT X-1,Y-1:FLAG=1
110 REM AND  3% OF THE BRANCHES DID           NOT CONTINUE TO GROW, BUT             REMAINED STUNTED GROWTHS.
111 COLOR 0:CHANCE3=RND(0)*100+1
112 IF X<40 AND X-3>1 AND CHANCE3>97 THEN PLOT X-3,Y-1:FLAG=1
113 IF X>40 AND X+3<78 AND CHANCE3>97 THEN PLOT X+3,Y-1:FLAG=1
114 IF X<40 AND X+1>1 AND CHANCE3>97 THEN PLOT X+1,Y-1:FLAG=1
115 IF X>40 AND X-1<78 AND CHANCE3>97 THEN PLOT X-1,Y-1:FLAG=1
120 REM IF A BRANCH WAS MADE, SKIP            OVER THE PART THAT DRAWS A            STRAIGHT STEM.
121 IF FLAG=1 THEN FLAG=0:GOTO 141
130 REM IF THE POINT IS OFF SCREEN,           DON'T PLOT IT.  OTHERWISE,            DO.
131 IF X<1 OR X>78 THEN GOTO SKIP
132 COLOR NODE:PLOT X,Y-1
140 REM JUMP TO THE SUBROUTINE THAT           MAKES THE STEM.
141 GOSUB STEM
150 REM END OF THE MAIN LOOP.
151 NEXT X
152 NEXT Y
153 GOTO 180
170 REM THIS IS THE SUBROUTINE FOR            MAKING THE 3-D STEM AROUND            EACH GROWTH NODE.
171 C=14:FOR X1=1 TO 14:C=C-2*(179/Y):IF C<0 THEN X1=14:GOTO 178
172 IF X-X1<1 THEN GOTO 175
173 LOCATE X-X1,Y,B:IF B>C THEN GOTO 175
174 COLOR C:PLOT X-X1,Y
175 IF X+X1>78 THEN GOTO 178
176 LOCATE X+X1,Y,B:IF B>C THEN GOTO 178
177 COLOR C:PLOT X+X1,Y
178 NEXT X1
179 RETURN
180 REM END OF THE PROGRAM.                   PUT YOUR FAVORITE SCREEN              DUMP ROUTINE HERE.
181 GOTO 181

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: DAHLIAS.BAS.

Credits