Julia Set Program for the Color Computer

The Julia Set rendered on a Radio Shack Color Computer Emulator System

As part of the continuing series of fractal programs for the TRS-80 Color Computer, I have converted a program found at RosettaCode that displays the Julia Set Fractal. The source originally was for a ZX Spectrum computer whose BASIC code was not all that different from the Color Computer Basic that Tandy uses for the CoCo.

The graphic above does not do the Julia set justice. The Julia set is a remarkable fractal shape with amazing levels of detail. The purpose of this program is simply to show it is possible to render a rough shape for the Julia Set with some relatively easy code. Remember, the original CoCo computers were running at around 1 mhz or so. These were never speedy or graphics rich computers. And yet, we managed to do some interesting things with them despite the limitations of the hardware and software.

If one compares the original code to the version I created for the CoCo, it is quite similar and takes into account the specific requirements for the Coco graphics. In line 90 of the code we set the Julia Set to be placed in the center of the screen to be plotted. This differs from the original ZX Spectrum that has a different graphical set of coordinates:

90 XOFFSET = 128 : YOFFSET = 95

Line 110 also sets the rough orientation of the fractal in terms of it’s portrayal at a certain viewing angle. One can play these values to try different views to get to know the code and experiment. Changing the values can provide views from more of a “top” view or edge-on view depending on the values selected.

110 CREAL=-0.8 : CIMAG=0.156

I have added sound to indicate the start of the render and a sound when the render is complete.

The Julia set plotted with Matplotlib. The seed coordinates are (-0.512511498387847167,      0.521295573094847167 – Click  the image to view source image at Wikicipedia.

What is the Julia Set?

Per Wikipedia: ”

In the context of complex dynamics, a branch of mathematics, the Julia set and the Fatou set are two complementary sets (Julia “laces” and Fatou “dusts”) defined from a function. Informally, the Fatou set of the function consists of values with the property that all nearby values behave similarly under repeated iteration of the function, and the Julia set consists of values such that an arbitrarily small perturbation can cause drastic changes in the sequence of iterated function values. Thus the behavior of the function on the Fatou set is “regular”, while on the Julia set its behavior is “chaotic“.”

Alternative Programs

Julia Set from Lizardic’s Program

Google for Julia Set programs and enjoy the wealth of free programs available to you. I like this little free program archived from Lizardic on Archive.org. It renders quickly and makes beautiful images.

A really neat online example can be found at Malnic with code that renders right in your browser. Once you see how detailed and beautiful these images are, you can appreciate the speed and limitations of what we had to work with in the 1980s with the CoCo.

There is a universe of these imaginative and interesting programs out there. What I’ve shared here is the most tentative dip into the water. Explore and enjoy!

Running the CoCo Program

An early generation Color Computer

This program takes LONG time to execute. I recommend getting a cup of coffee and walking off to let the program bubble away, creating the image. Listen for the beep when the render is complete.

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

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

The Code

10 REM COCO JULIA PROGRAM
20 REM MODIFIED BY JON ALMADA FROM EXAMPLE AT ROSETTACODE
30 REM FOR JULIA SET. SEE ZX SPECTRUM BASIC EXAMPLE
40 REM SET THE GRAPHICS MODE FOR THE COCO
50 CLS : PRINT “WELCOME TO COCO-JULIA” : PRINT “CLICK TO CONTINUE”
60 PRINT “GET COFFEE AND CHILL WHILE JULIA SET PLOTS.” : INPUT A
70 PMODE 0,1 : PCLS : SCREEN 1,1
80 REM SET THE X AND Y OFFSETS TO POSITION THE IMAGE
90 XOFFSET = 128 : YOFFSET = 95
100 REM SCALED X AND SCALED Y IMAGINARY
110 CREAL=-0.8 : CIMAG=0.156
120 REM SOUND OFF TO LET THE USER KNOW THE PROGRAM IS STARTING
130 SOUND 32,10
140 FOR V=-16 TO 16
150 FOR H=-64 TO 64
160 X=H/40
170 Y=V/20
180 FOR I=1 TO 50
190 ZREAL=X*X-Y*Y+CREAL
200 ZIMAG=X*Y*2+CIMAG
210 IF ZREAL*ZREAL>1000 THEN GOTO 260
220 X=ZREAL
230 Y=ZIMAG
240 NEXT I
250 PSET (H+XOFFSET,YOFFSET-V,1)
260 NEXT H
270 NEXT V
280 REM SOUND OFF THAT THE JULIA SET IS DONE
290 SOUND 33,22
300 GOTO 300