Mandelbrot – A Fractal World, Part Two

The BASICs

[Note: in the scanned issue the right-hand column is cut off at the binding; words shown in square brackets are reconstructed.]

[Note: in the scanned issue the right-hand column is cut off at the binding; words shown in square brackets are reconstructed.]

I hope you have been experiencing great adventures exploring the new frontiers opened up by fractal geometry. In this part of the article we will examine the BASIC program.

For those of you who are learning the ropes of SuperBASIC, I will point out some of the highlights of the BASIC Mandelbrot program featured in the previous issue of Time Designs (Nov/Dec 1987 pp 23-28). It was my intent to write a program using the power and flexibility of SuperBASIC. To demonstrate the power of SuperBASIC, the major portion of the BASIC program is comprised of only 2 lines (lines 60 & 70). The rest of the program is solely support procedures for these two lines of BASIC. The program contains 18 procedure modules and 1 function module. Advantages of writing programs in this manner include the ease of extending and following the program when it comes time to de-bug.

Our first procedure is initial, which sets up the computer to run the program. Line 2550 declares the variables x, y & i to apply only to the PROCedure initial. If these variable names are used elsewhere in the program, the values set in the PROCedure will not apply. By using the SuperBASIC command LOCal, one does not have to worry about re-declaring a variable which is needed elsewhere in the program. However one must be careful when using this command. If the PROCedure is called again and the value of a LOCal variable is to be used with the contents when the PROCedure was exited, the original value is lost. From within the initial PROCedure, another PROCedure (tv) is called, which simply redefines the default windows to fit within a U.S. TV screen and sets the MODE to 8 colors. The rest of the initial PROCedure “draws” the title screen, loads the 3 machine code routines into memory, defines and POKEs into the “plotter” machine code routine the default color schemes for the Mandel[brot] set, and sets up the default device and name for saving resul[t] data.

PROCedure main_prog is the work-horse of the program. [It] consists of an endless loop which controls the branching of [the] program. This was achieved by not providing an exit to [the] REPeat bigloop.

Main_menu is the PROCedure which prints the menu and redir[ects] the program based on the user’s input. The “shadows” in the [illegible] are created by using the STRIP and CURSOR commands. [By] offsetting the cursor location 4 pixels and setting the s[illegible] color, a shadow is drawn and then the text is written over [the] shadow (see lines 1960-2070). The REPeat response loop reads [the] keyboard for correct input and branches accordingly. Line [illegible] calls the FuNction keyini which translates any key pressed [illegible] its ASCII code and returns the result in variable a and is pa[ssed] to the variable key (see line 4410). Lines 2240-2300 return [from] this PROCedure to an approriate PROCedure based on what bran[ches] were made due to user input. Line 2280 allows a PROCedure t[o be] re-entered if the value of key was changed to 100 (see line [illegible] of PROCedure redraw).

The set_up PROCedure provides a means for directing the se[arch] for a particular part of the fractal world and for the chan[ging] of default device and data name. A machine code routine w[hich] sets up machine code variables for a fresh start is also ca[lled] from within this PROCedure. (NOTE: This PROCedure has one m[illegible] weak link, no checks are made for correct user input. If [the] user inputs blank lines or letters instead of numbers, [the] program will crash. Those of you who are industrious may wis[h to] write a couple of “Check” PROCedures to insure proper input.)

To insure the flow of the program, the back_door PROCe[dure] provides a “Sub-Routine” which steps through the creation of [the] Fractal data and screen. When this PROCedure is exited [by] “falling-out” through the end (line 1190), the program [will] continue from the branch created within main_prog, contin[uing] with a call of the PROCedure store_it. After a complete fra[ctal] map has been created, a prompt will appear on the sc[reen] prompting the user to ready the device for the saving of [data] (see Lines 1182 & 1184) and for a key press to continue (see [illegible] 1186). (NOTE: To insure that the messages printed in [the] “mini_window” can be seen (includes the above prompt and [the] “mini_menu”), the computer must be intialized in TV Mode ([illegible] Due to the difference in line spacing between Monitor an[d TV] Modes, a full mini_menu will not appear if the computer i[s in] Monitor Mode.)

The mini_window PROCedure calls a machine code routine w[hich] makes a copy of screen data in the area to be overwritten by [the] new window opened by line 1890. This data is restored by [the] machine code routine called by the paste PROCedure. N[OTE:] Correction to a cosmetic error in listing 1 — Line 4510 sh[ould] read “END DEFine paste”. This correction is only for consist[ency] as the program will run fine as written.

Before data is saved to microdrive (or specified device), a c[heck] is made by the store_it PROCedure to insure that an error re[port] is not generated if files already exist with the same name. [This] is accomplished by lines 1390-1540 and the PROCedure check_[dev.] If files of the same name do exist, the user is allowed to re[illegible] the data to be saved or allow the existing files to be del[eted] from the medium before a save is executed.

The last major PROCedure left is re_color which allows the [user] to redefine the color scheme for the points within and out[side] the Mandelbrot set. There are a total of 255 different poss[ible] calculated “distance” points. If they have not yet been arra[nged] into a table of dispersion, this calculation is carried ou[t by] lines 3770-3930. The resulting calculations will provide a [rough] guide to help in re-defining the color scheme. Lines 4060-[illegible] will build up a new color scheme based on the user’s input.

The remainder of the PROCedures should be easy to decipher b[ased] on the above information and by following their logical flow[. I] hope that by following the program carefully and by experimen[ting] with the various SuperBASIC commands included within the pro[gram] that readers who are striving to learn the power of the [illegible] BASIC programming language will have a head start.

fig. 1 - Sinclair QL computer
fig. 1 – Sinclair QL computer

PROCedure and FuNction list

PROCedure              Line Nos.

back_door              1080-1190
canvas                 4640-4670
check_dev              1690-1840
color-bar              4280-4330
done                   1210-1360
initial                2540-2850
main_menu              1930-2310
main_prog              1000-1060
mini_menu              2330-2520
mini_window            1860-1910
paste                  4490-4510
re_color               3740-4260
recall                 3150-3490
redraw                 3510-3720
set_up                 2870-3130
snap_shot              4450-4470
store_it               1380-1670
tv                     4530-4620


FuNction

keyini                 4350-4430