More Fractal Programs for the Color Computer – The Leaf Program

A beautiful digital fern that you can create on your Color Computer from a simple BASIC program.

Some programs are so fiendishly simple that you just have to smile when you see them.

This program by a gentleman named Bill Sexton is one such program found at the Color Computer Archive web site. It draws a fractal leaf on the display and NEVER quits running. As I am writing this, the program is slowly moving along with displaying the beautiful image of what is called a “Barnsley Fern.ย  This fractal is named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS).

Making the Barnsley Fern

The procedure to create Barnsley’s Fern is as follows:

  • Pick a starting point
  • Choose a coordinate transformation according to probability
  • Multiply the starting point by the matrix transformation
  • Add the result by the matrix translation
  • Repeat or iterate infinitely using the resulting point as the new starting coordinates

In 9 lines of code, this elegant little program manages to capture the essence of lightweight computing and displays a beautiful fractal image.

Line 10 sets up the CoCo graphics display in 2 color mode of green and black. Line 20 starts the X and Y coordinates off at zero. Line 30 marks the start of the looped (and never-ending execution of the routine and creates a random number somewhere between 0 and 1.

Lines 40 through 70ย  are the coordinate transformations. More on these can be found HERE to fully flesh out their function however, I will take a stab at a shorthand explanation:

  • Line 40 draws the spine of the “fern”.
  • Line 50 draws the vast bulk of the fern leaves projecting out from the second leaf structures and on to the ending tip of the fern.
  • Line 60 draws the top left fern leaf.
  • Line 70 draws the bottom left fern leaf.

Line 80 sets the actual X,Y point to a green dot.

Line 90 returns to complete the endless cycle all over again.

Fractal Dimension of the Barnsley Fern

The Fractal Dimension of the Barnsley Fern cannot be calculated by conventional means, and is estimated to be about 1.45.

Program Listing

5 REM LEAF PROGRAM BY BILL SEXTON
10 PMODE 4,1:SCREEN1,0:PCLS
20 X=0:Y=0
30 R=RND(0)
40 IF R<.01 THEN X=0:Y=.16*Y:GOTO 80
50 IF R<.86 THEN T=.85*X+.04*Y:Y=-.04*X+.85*Y+1.6:X=T:GOTO 80
60 IF R<.93 THEN T=.2*X-.26*Y:Y=.23*X+.22*Y+1.6:X=T:GOTO 80
70 T=-.15*X+.29*Y:Y=.26*X+.24*Y+.44:X=T
80 PSET(25*Y, 105-35*X)
90 GOTO 30

Running the program

As most people do not own a working vintage Color Computer, the VCC Color Computer Emulator will suffice and is, more importantly, FREE.

You can download Bill Sexton’s virtual floppy disk code with the “LEAF.BAS” program and run it from the virtual floppy drive or scrape the code here to run the program.

This software emulates all types of Color Computer systems and comes with built-in BASIC to allow one to run original Radio Shack software or create their own from scratch. The software emulates all manner of varieties and peripherals that the COCO supported during itโ€™s heyday.

Scrape and then paste the code into the VCC emulator and then type โ€œRUNโ€ to execute the code. I recommend you get a cup of coffee and return to slowly watch the art emerge as the formula iterates and feeds into itself over time.

Enjoy the code and I hope this inspires you to use simple retro systems like the Color Computer to explore math and science concepts. โ€” Jon