*** Fractal Microscope ***
   Programmed by Terry Newton

The Mandelbrot Set is a very complicated imaginary mathematical object
located on the complex number plane, a two dimensional space of real and
imaginary numbers. The Mandelbrot Set is a fractal object. Areas of interest
can be magnified to produce images with just as much detail. With this program
enlagements of over 100,000 times over the parent image are possible. Each
point can also be expanded into a Julia Set, which itself can be magnified
upon. The Mandelbrot Set represents a table of contents to an infinite variety
of Julia Sets. Using this program you can explore this strange universe of
fractals and possibly see images never seen before.

For more information on the Mandelbrot set refer to Scientific American
August 1985, February 1989 and many other articles published on the subject.

Because of the intense mathematics required to compute the images, be prepared
to wait some. Each image takes several hours of computation. I have made every
effort to speed up the process including using fixed point math in machine
code. This is probably the fastest version available for an 8 bit computer.
Once an image is made, it becomes part of your collection to be enjoyed at
any time, so the time is not that much compared with the results obtained.
For convienience you may save an incomplete image and finish it later,
in case you must use the computer for something else.

SCOPE.COM must be loaded with basic disabled, hold down the option key when
powering up the computer. After loading you will see the main menu with the
following choices...

N - New   P - Plot  D - Data  V - View
S - Save  L - Load  F - Files 1-8 - D1:
C - Color X - Exit  M - Magnify

The default drive for saves, loads and files is selected by pressing a
digit between 1 and 8. Files lists all the *.PIC files on the selected drive.
Under SpartaDOS the Exit option allows you to go to DOS without disturbing
the image, do DOS fuctions (except COPY!) then return with the RUN command.
Under DOS 2.5 Exit functions the same as pressing the reset key and the image
will be lost if not saved. The View option simply displays the image without
the menu.

The following variables are used by SCOPE to define the image...

Real Center - Location on the 'X' axis
Imag Center - Location on the 'Y' axis
Plot Range  - Length of each side
CA          - Real point for Julia
CB          - Imag point for Julia
Band Factor - Determines range of bands
Iter. Limit - Cutoff for iterations

These variables and the current X and Y pixel numbers are shown by the Data
option. New plot lets you manually enter or change variables. Press Return to
keep old value. The variables are initially set to produce the overall image.

The Plot option begins calculation from the last point. If it is a new plot
you can select to estimate the plot time, produce a 1/16 size test plot or
just begin plotting. Mini-plots can be saved and magnified from as with full
size plots but require much less time to make and are helpful in getting an
idea of what the area looks like before making the real thing. The time given
is only approximate.

Save and Load use a compression routine to store and retrieve image files
with variables. The save option displays the last loaded file if the variables
haven't changed. The default drive is selected from the main menu and a *.PIC
extension is used if none specified.

Magnify allows you to enlarge an area for closer inspection or convert a
point into a Julia Set plot. When selected a cursor appears on the image.
Move with the cursor keys and press Return to read out the point coordinates.
Press F to find another point, I to count the iterations for that point, J to
use the point for a new Julia plot, and M to enter a magnification factor to
enlarge the area. Julia and Magnify prompt for additional variables, press
Return to keep the old values or enter a new value. Begin plotting by
selecting the Plot option.

The Color option lets you change the color registers. C chooses the color
register, H changes the hue and L changes the luminance. You can see the
changes as you make them. S lets you save the colors internally as default
colors when changing resolution. Restore recalls the default colors.

The default colors can be permanently changed by using the BASIC program
CHANGE.BAS. Before using have the color hue and luminosity numbers figured
out from the Color option. CHANGE.BAS tries to read and display the old
values, accepts new values for color and mono resolutions then writes out
the new file. COL.OBJ must be appended to SCOPE.COM to effect the changes.
Under DOS 2.5 use the copy option C then enter COL.OBJ,SCOPE.COM/A for
source and destination. Under SpartaDOS enter COPY COL.OBJ SCOPE.COM/A
to append the file. Do this to a working copy of the program and don't
forget the /A.


Image File Format...

1 Byte      Graphics Mode 8 or 15
3 Bytes     Color Registers CR0-CR2
1 Byte      254 to flag compression
1 Byte      Color Resister CR4
2 Bytes     Length of RL data
Variable    RL encoded bitmap
Variable    Plot Data in text form

Run Length Encoding is used with the image scanned in byte columns
(every 40th byte) for maximum compression effect. Runs of 3 or more bytes
are replaced with the sequence 254,byte,length. Byte 254 is replaced with
254,254,1. Files are typically a third to half the size of normal bitmaps.
This is a modified version of an old routine written by Cris Zamara and
works very well for images. The routines will not work if BASIC is enabled.

Because of the time consuming nature of making iterated fractal images
(especially on an 8 bit system) every effort has been made to speed up the
process. Machine code does the actual calculations using 24 bit fixed point
numbers (5 bit whole, 19 bit fraction with an extra byte for sign). This
number system allows for over 100,000 times enlargement with no noticable
loss of resoulution and the code runs three times faster than floating point.

Other methods help to increase the speed of plotting images containing
substantial amounts of the set. Attractor detection is used in the iteration
code to exit early if a repeating loop in the iterate is found. Most points
within the set will go into a repeating loop at some point well before a high
limit is reached. Attractor detection is turned on when a point goes to limit
and turned off when the next non-set point is encountered to prevent the
detection code from slowing down non-set plotting. Finally, whenever plotting
set points, only every other point is checked to cut set time by half. When
the next non-set point is encountered the last skipped point is checked to
keep the edges sharp.

The formula used to get the count value for each pixel is Z=Z^2+C until
Z exceeds a size of 2. Z and C are complex numbers with real and imaginary
components. To make a Mandelbrot plot Z starts at 0 and C sweeps through all
pixels. To make a Julia plot C is held at some fixed value and the starting
value of Z is varied. In either case each pixel's count value is used to
determine the pixel's color. The following are psuedocode versions of the
machine code routines...

 AC,BC - Real,Imaginary point C
 Limit - Maximum Iterations
 AZ,BZ - Starting Value for Z
 AS,BS - Holds squares of AZ,BZ
 Count - Iteration Number
 Attflag - Attractor Detect on/off
 AA(1..Limit) - Holds values of AZ
 AB(1..Limit) - Holds values of BZ
 Count=0  AS=AZ^2  BS=BZ^2
 While AS+BS<4 and Count<Limit
  AS=AZ^2  BS=BZ^2  Count=Count+1
  If Attflag=1
   AA(Count)=AZ  AB(Count)=BZ
   If AZ=AA(Count/2) and BZ=AB(Count/2)
 If Count=Limit Attrflag=1
 Else Attrflag=0
Return Count

 Count - Iteration count
 Bandf - Banding Factor
 Color - Resulting color 1 to 3
 Q     - Internal counter variable
 Q=0  Color=0
 While Q<Count
  Color=Color+1 Mod 3
Return Color

The program colors points that reach the limit color 0 and those that don't
with color 1 to 3 based on the transform function. When plotting in monochrome
every other point that reaches the limit is turned on (to simulate gray) and
the other points are plotted only if the transform color changes resulting
in an outline view of the area.

The code used to create SCOPE.COM consists of many files, some of which
are common to other programs in this collection. Link file...

SCOPE.CCC     Main program body
SCSUB.CCC     Routines for SCOPE
PLOTSUB.CCC   General plot routines
ITER7000.OBJ  Iteration Machine Code
GR7P6F00.OBJ  Code to simulate GR15
CMP6D40.OBJ   Compression Code
ENGINE.OBJ    ACE C Runtime w/run adr
COL.OBJ       Default Colors (06F0)

Source Files...



1. ENGINE.OBJ file is a debugged version and must be used (some integer
conversion routines in the original did not work right).

2. Either the ACE C or the Lightspeed C compiler can be used to compile
the C source code. The ACE C library and runtime was used because it is
public domain and produces smaller program files, You must use the FASTC
optimizer on the .CCC code (twice on SCOPE) or there will not be enough
memory to link or it will run into the 6D40 ML code.

3. Graphics mode 15 is simulated by using graphics mode 8 and a neat
relocatable routine called GR7PLUS located at 6D40 hex. This allows high
resolution color graphics to be displayed on any Atari 8 bit computer.
I'm not sure where the routine originally came from but thanks to whoever
wrote it. All plotting is done with graphics mode 8 double pixels using
the PLOTSUB.C routines.