home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Crawly Crypt Collection 2
/
crawlyvol2.bin
/
graphics
/
fractal2
/
fractal2.lst
< prev
next >
Wrap
File List
|
1985-11-17
|
18KB
|
718 lines
'
' Mandelbrot set (fractal) generator program
' Originally programmed in "C" by Tom Hudson (January, 1986 ANALOG Computing).
'
' Converted to GFA and enhanced (GEM support, etc.) by Blake Arnold
' (co-author of Ultra-Graph from the November, 1988 ST-Log).
'
' 10-18-89
'
' ************* NOTICE ************ NOTICE ************ NOTICE ************
' Portions of this program are Copyright 1989 by Tom Hudson, ANALOG
' Computing, Blake Arnold, and Phil Mast. This program is not public
' domain but may be freely distributed. It may not be sold in any way.
' *************************************************************************
'
' -------------------------------------------------------------------
Gosub Main
Procedure Main
' Initialize
Res%=Xbios(4) !Get the resolution
If Res%<>0
Alert 3,"|Use low resolution.",1," Ok ",Dum%
Edit
Endif
Dim S_colr%(15,2),Rgb%(2)
Dim Colrtable%(15)
Dim Sav%(15,3),Sa%(16)
Dim D$(34)
' Menu data
D$(0)="Desk"
D$(1)=" About Fractals "
D$(2)="----------------"
D$(3)="-" ! "-" disables that menu item (disables ACC's here)
D$(4)="-"
D$(5)="-"
D$(6)="-"
D$(7)="-"
D$(8)="-"
D$(9)="" !menus are seperated by a null
D$(10)="File"
D$(11)=" Degas Save "
D$(12)="-----------------"
D$(13)=" Save Fractal "
D$(14)=" Save Parameters "
D$(15)="-----------------"
D$(16)=" Load Fractal "
D$(17)=" Load Parameters "
D$(18)="-----------------"
D$(19)=" Quit "
D$(20)=""
D$(21)="Options"
D$(22)=" Spectrum "
D$(23)=" Yellow "
D$(24)=" Gradient "
D$(25)=" Sys. Default"
D$(26)="--------------"
D$(27)=" Draw it! "
D$(28)="--------------"
D$(29)=" Input Data "
D$(30)=" Iterations "
D$(31)=" Defaults "
D$(32)=""
' store original color palette
For I%=0 To 15
Dpoke Contrl,26
Dpoke Contrl+2,0
Dpoke Contrl+6,2
Dpoke Intin,I%
Dpoke Intin+2,0
Vdisys
S_colr%(I%,0)=Dpeek(Intout+2)
S_colr%(I%,1)=Dpeek(Intout+4)
S_colr%(I%,2)=Dpeek(Intout+6)
Next I%
Colrtable%(0)=0
Colrtable%(1)=2
Colrtable%(2)=3
Colrtable%(3)=6
Colrtable%(4)=4
Colrtable%(5)=7
Colrtable%(6)=5
Colrtable%(7)=8
Colrtable%(8)=9
Colrtable%(9)=10
Colrtable%(10)=11
Colrtable%(11)=14
Colrtable%(12)=12
Colrtable%(13)=15
Colrtable%(14)=13
Colrtable%(15)=1
Gosub Palette
Cls
Palette%=0
Scrn%=1
Sget Screen1$
Iterations!=True
Fractal!=False ! we havent drawn a fractal yet
If Exist("MANDEL.MBS")
' Why waste time redrawing the set? We'll cheat and load it right in!
Fractal!=True
Filename$="MANDEL.MBS"
Gosub Load_screen
Close #1
Else
Fractal!=False
Endif
Gosub Screenswap
' Let the program know where to go on a drop-down selection
On Menu Gosub Set_options
Gosub Defaults
Gosub Mark_menu
' ----Main Loop for the option menu----
Do
On Menu
If Mousek=2
Gosub Screenswap
Endif
If Mousek=3
Gosub Process
Gosub Hold_it
Endif
Loop
Return
Procedure Set_options
' OOOOOOOOOOOOOOOOOOOOOOOOOOO-Set Options-OOOOOOOOOOOOOOOOOOOOOOOOOOO
' Drop-down menu selections
Menu Off
If D$(Menu(0))=D$(1) ! About Fractals
Read_again:
Cls
Print " This program was originally written"
Print "by Tom Hudson and published in the"
Print "January, 1986 issue of 'ANALOG"
Print "Computing'. Portions of this program"
Print "are Copyright 1989 by Tom Hudson,"
Print "ANALOG Computing, Blake Arnold, and"
Print "Phil Mast. The program may not be"
Print "sold in any way, but may be freely"
Print "distributed as long as the copyright"
Print "notices remain intact."
Print " I have taken the liberty to convert"
Print "Tom's math/drawing routines into GFA"
Print "Basic, and add a few features that"
Print "make the program a little easier to use."
Print " Please refer to the included"
Print "documentation file for detailed"
Print "instructions on using the program."
Print
Print " - Blake Arnold (Delphi '1BLAKE')"
Print
Print " Press any key to exit"
' ******
Do
Exit If Inkey$<>""
Loop
Gosub Params
Endif
If D$(Menu(0))=D$(11) ! Save Picture
Dum%=1
If Fractal!=False
Alert 3,"|No Fractal has been|drawn with these|parameters. ",1,"Save |Abort",Dum%
Endif
If Dum%=1
Extender$=".PI1"
Choice%=0
Gosub Open_file
Endif
Endif
If D$(Menu(0))=D$(14) ! Save Parameters
Extender$=".MBP"
Choice%=2
Gosub Open_file
Endif
If D$(Menu(0))=D$(17) ! Load Parameters
Choice%=4
Extender$=".MBP"
Fractal!=False
Gosub Open_file
Endif
If D$(Menu(0))=D$(13) ! Save Fractal
If Fractal!=True
Choice%=1
Extender$=".MBS"
Gosub Open_file
Else
Alert 3,"|No Fractal has been|drawn with these|parameters. ",1,"Abort",Dum%
Endif
Endif
If D$(Menu(0))=D$(16) ! Load Fractal
Fractal!=False
Choice%=3
Extender$=".MBS" ! MBS - MandelBrot Set
Gosub Open_file
Endif
' I can't forsee anyone wanting to stop drawing fratcals, but just in case..
If D$(Menu(0))=D$(19) ! Quit
Alert 2,"| Quit Fractals? ",1,"Yes|No ",Dum%
If Dum%=1
' Restore original color palette
For I%=0 To 15
Dpoke Contrl,14
Dpoke Contrl+2,0
Dpoke Contrl+6,4
Dpoke Intin,I%
Dpoke Intin+2,S_colr%(I%,0)
Dpoke Intin+4,S_colr%(I%,1)
Dpoke Intin+6,S_colr%(I%,2)
Vdisys
Next I%
Menu Kill
Menu Off
Cls
Edit
Endif
Endif
If D$(Menu(0))=D$(24) ! Gradient
Alert 2,"| Which Color? ",1,"R|G|B",Palette%
Gosub Palette
Endif
If D$(Menu(0))=D$(22) ! Spectrum
Palette%=0
Gosub Palette
Endif
If D$(Menu(0))=D$(23) ! Yellow
Alert 2,"| Positive or Negative? ",1,"Pos.|Neg.",Palette%
Palette%=Palette%+3
Gosub Palette
Endif
If D$(Menu(0))=D$(25) ! System Default
For I%=0 To 15
Palette%=7
Dpoke Contrl,14
Dpoke Contrl+2,0
Dpoke Contrl+6,4
Dpoke Intin,I%
Dpoke Intin+2,S_colr%(I%,0)
Dpoke Intin+4,S_colr%(I%,1)
Dpoke Intin+6,S_colr%(I%,2)
Vdisys
Next I%
Gosub Mark_menu
Endif
If D$(Menu(0))=D$(27) ! Draw it
Gosub Process
Gosub Hold_it
Endif
If D$(Menu(0))=D$(29)
Iterations!=False
Gosub Inp_data
Gosub Params
Endif
If D$(Menu(0))=D$(30) !Iteration input
Iterations!=True
Gosub Inp_data
Gosub Params
Iterations!=False
Fractal!=False
Endif
If D$(Menu(0))=D$(31) ! Defaults
Alert 2,"| Restore Defaults? ",2,"Yes|No",Dum%
Fractal!=False
If Dum%=1
Gosub Defaults
Endif
Endif
Return
Procedure Inp_data
' ******* Map parameter input ********
Fractal!=False
Cls
If Iterations!=False
Print
Print
Print "Previous values:"
Print "Real Center : ";Ixs
Print "Real Range : ";Rrange
Print "Imag. Center: ";Iys
Print "Imag. Range : ";Ye-Ys
Print "Iterations : ";Climit%
Print
Print
Print "Enter new values:"
Input "Real Number Center";Ixs
' Ixs=-0.75 !**** (default parameters)
Input "Real number range";Rrange
' Rrange=3.25 !****
Input "Imaginary number center";Iys
' Iys=0 !****
Input "Iteration limit";Climit%
' climit=100 !****
Else
Print
Print
Print "Change iteration limit"
Print
Print "Previous iteration limit: ";Climit%
Input "New iteration limit";Climit%
Endif
Return
Procedure Params
Cls
Xs=Ixs-Rrange/2
Xe=Xs+Rrange
Xstep=(Xe-Xs)/319
Ys=Iys-(Rrange*0.77)/2
Ye=Ys+Rrange*0.77
Ystep=(Ye-Ys)/199
Cdivfac%=Climit%/16
Print At(1,6);"Mandelbrot Set Parameters:"
Print At(1,9);"Real Center : ";Ixs
Print At(1,10);"Real Range : ";Rrange
Print At(1,11);"Imag. Center: ";Iys
Print At(1,12);"Imag. Range : ";Ye-Ys
Print At(1,13);"Iterations : ";Climit%
Menu D$()
Gosub Mark_menu
On Menu Gosub Set_options
Return
' ********* Process the pixel map ********
Procedure Process
' what a mess! Spaghetti code at it's best!
Menu Kill
Cls
Hidem
Fractal!=True
Pass%=1
Mark1:
Xp%=0
X=Xs
If Pass%=1
Xp%=1
X=X+Xstep
Endif
If Pass%=3
Xp%=1
X=X+Xstep
Endif
While Xp%<320
' X=X+Xstep
X=X+2*Xstep
Yp%=199
Y=Ys
If (Pass%=2 Or Pass%=3)
Yp%=198
Y=Y+Ystep
Endif
While Yp%>-1
' Y=Y+Ystep
Y=Y+2*Ystep
Az=0
Bz=0
Ac=X
Bc=Y
Count%=0
Size=0
While Count%<Climit% And Size<2
At=Az*Az-Bz*Bz
Bt=Az*Bz*2
Az=At+Ac
Bz=Bt+Bc
Tsiz=Az*Az+Bz*Bz
Size=Sqr(Tsiz)
Inc Count%
Wend
Pcolor%=Count%/Cdivfac%
If Pcolor%>15
Pcolor%=15
Endif
' the following 2 REMs should be active if this is merged into GFA 2.x
Color Colrtable%(Pcolor%) ! GFA 2.x only
Plot Xp%,Yp% ! GFA 2.x only
' else use this for GFA 3.x (it's a tiny bit faster)
' PSET xp%,yp%,pcolor% ! GFA 3.x only
Dec Yp%
Dec Yp%
Wend
Inc Xp%
Inc Xp%
If Mousek=2
Pass%=5 ! makes it jump out of the loop
Xp%=320
Endif
Wend
Inc Pass%
If Pass%<5
Goto Mark1
Endif
For I%=15 To 0 Step -1
Sound 1,I%,7,5
Pause 1
Next I%
Sget Screen1$
Return
' ****************************************************
Procedure Hold_it
Pause 30
Do
Hidem
If Mousek=1 And Fractal!=True
Defmouse "=7"
Gosub Magnify
Sget Screen1$
Goto Done
Endif
Exit If Mousek=2
Loop
Done:
Defmouse 0
Gosub Screenswap
Showm
Return
' **********************************************
Procedure Magnify
Showm
Defmouse 7
Print At(1,1);"◆◆";
Pause 30
Print At(1,1);"Center"
Do
' Get "center" values
Micex=Mousex
Micey=Mousey
Exit If Mousek=1
Loop
Print At(1,1);"◆◆";
Pause 30
' clear mouse clicks
Pause 30
Print At(1,1);"Range "
Do
' Get "range" values
Micex2=Mousex
Micey2=Mousey
Exit If Mousek=1
Loop
Print At(1,1);"◆◆";
Pause 30
Gosub New_val
Return
Procedure New_val
' this could be simplified, but it works like it is.
Pxlvalx=Rrange/319
Pxlvaly=Rrange*0.77/199
Rrange1=Rrange
Pxlrange=2*Abs(Micex-Micex2)
Xval=Ixs-Rrange/2
Rrange=Pxlrange*Pxlvalx
Ixs=Xval+(Pxlvalx*Micex)
Xs=Ixs-Rrange/2
Xe=Xs+Rrange
Xstep=(Xe-Xs)/319
Iys=Ye-(Pxlvaly*Micey)
Ys=Iys-(Rrange*0.77/2)
Ye=Ys+Rrange*0.77
Ystep=(Ye-Ys)/199
Boxy=Int(Abs(0.63*((Micex2-Micex)*2)))
' looks tricky, eh? It's not.. it's just quick & dirty
Color 1
Deffill 1,0,0
Box Micex-(Micex2-Micex),(Micey-Boxy/2),(Micex2),(Micey+Boxy/2)
Pause 200
Cdivfac%=Climit%/16
Fractal!=False
Return
Procedure Load_degas
' This was hacked from an old P/D picture-display program
' by Richard Noe, EAFB Alaska (5 Jan, 1986)
'
File$="FRACTAL1.PI1"
Bload File$,Xbios(2)-34
A%=Xbios(2)-32
For X=0 To 15
Sa%(X)=Dpeek(A%)
A%=A%+2
Next X
For X=0 To 15
A=Xbios(7,X,Sa%(X))
Next X
Pause P%*250
Return
'
Procedure Res
If Xbios(4)<>0 Then
Alert 3,"You must be in | Low rez ",1,"uh oh",Dummy%
Quit
Endif
Return
'
Procedure Open_file
' ooooooooooooooooooooooooooo-Open file-ooooooooooooooooooooooooo
' straight out of Ultra-Graph (November, 1988 issue of ST-Log)..
' of course, this _is_ a little overly complex for what we're doing here,
' but it works like it is so..
On Error Gosub Disk_err
Drive$=Chr$(Gemdos(25)+65)
Filename$=""
If Dir$(0)<>""
Graphfil$=Drive$+":"+Dir$(0)+"\*"+Extender$
Else
Graphfil$=Drive$+":\*"+Extender$
Endif
Select:
Fileselect Graphfil$,"",Filename$
If Filename$<>""
If Filename$<>Drive$+":" And Right$(Filename$)<>"\"
Period%=Instr(Filename$,".")
If Period%=0
Filename$=Filename$+Extender$
Else
If Choice%<>3 And Choice%<>4
Filename$=Left$(Filename$,Period%-1)+Extender$
Endif
Endif
Backslash%=-1
Repeat
Dum%=Backslash%
Inc Dum%
Backslash%=Instr(Dum%,Filename$,"\")
Until Backslash%=0
Chdrive Asc(Left$(Filename$))-64
Path$=Mid$(Filename$,Instr(Filename$,"\"),Dum%-Instr(Filename$,"\")-1)
If Path$<>""
Chdir Path$
Else
Chdir "\"
Endif
Defmouse 2
If Choice%=0 Or Choice%=1 Or Choice%=2
Open "O",#1,Filename$
On Choice%+1 Gosub Degas_save,Save_screen,Save_params
Else
If Exist(Filename$)
If Choice%=3
Gosub Load_screen
Else
Gosub Load_params
Endif
Else
Alert 1,"|File not found",1,"OK",Dum%
Endif
Endif
Endif
Endif
Abort_open:
Close #1
Defmouse 0
On Error
Return
' ssssssssssssssssssssssssss-Degas Save-sssssssssssssssssssssssss
Procedure Degas_save
' --- DEGAS file write ---
Degasheader$=Mki$(Res%)
For I%=0 To 15
Gosub Get_color
Degasheader$=Degasheader$+Mki$(Hue%)
Next I%
Bput #1,Varptr(Degasheader$),34
Bput #1,Varptr(Screen1$),32000
Close #1
Return
Procedure Disk_err
' ----- Disk error procedure -----
Defmouse 0
' If the disk was write protected GEM already gave them an alert box so skip this one
If Err<>-13
Alert 3," Disk Error. | Operation aborted. ",1," Ok ",Dum%
Endif
Resume Abort_open
Return
Procedure Get_color
' ----- Get colors -----
Dpoke Contrl,26
Dpoke Contrl+2,0
Dpoke Contrl+6,2
Dpoke Intin,Colrtable%(I%)
Dpoke Intin+2,1
Vdisys
Rgb%(0)=Dpeek(Intout+2)
Rgb%(1)=Dpeek(Intout+4)
Rgb%(2)=Dpeek(Intout+6)
For J%=0 To 2
Rgb%(J%)=Int(Rgb%(J%)/142)
Next J%
Hue%=Rgb%(0)*&H100+Rgb%(1)*&H10+Rgb%(2)
Return
' ggggggggggggggggggggggggg-Graph Save-gggggggggggggggggggggggggg
Procedure Save_params
Write #1,Ixs,Rrange,Iys,Climit%
Close #1
Return
' RRRRRRRRRRRRRRRRRRRRRRR-Read in a Graph-RRRRRRRRRRRRRRRRRRRRRRRR
Procedure Load_params
Open "I",#1,Filename$
Input #1,Ixs,Rrange,Iys,Climit%
Close #1
Gosub Convert_params
Gosub Params
Return
Procedure Convert_params
Xs=Ixs-Rrange/2
Xe=Xs+Rrange
Xstep=(Xe-Xs)/319
Ys=Iys-(Rrange*0.77)/2
Ye=Ys+Rrange*0.77
Ystep=(Ye-Ys)/199
Cdivfac%=Climit%/16
Return
Procedure Screenswap
If Scrn%=0 !If we are on the menu screen
Menu Kill
Menu Off
Sput Screen1$ !Return the graph screen
Scrn%=1
Gosub Hold_it
Else
Scrn%=0
Cls
Gosub Params !Reprint the menu screen
Pause 30
Endif
Return
' ++++++++++++++++++++++++++++-Palette-++++++++++++++++++++++++++++
Procedure Palette
If Palette%=1
Restore Red
Else
If Palette%=2
Restore Green
Else
If Palette%=3
Restore Blue
Else
If Palette%=4
Restore Yellow
Else
If Palette%=5
Restore Yellow_rev
Else
If Palette%=0
Restore Spectrum
Else
' If Palette%=7
' Restore Rainbow
' Endif
Endif
Endif
Endif
Endif
Endif
Endif
For I%=0 To 15
Read Colr%
Setcolor I%,Colr%
Next I%
Yellow_rev:
Data &200,&210,&310,&410,&510,&610,&710,&720,&730,&740,&750,&760,&772,&774,&776,&000
Yellow:
Data &776,&774,&772,&760,&750,&740,&730,&720,&710,&610,&510,&410,&310,&210,&200,&000
Spectrum:
Data &715,&707,&507,&327,&007,&027,&057,&077,&075,&070,&571,&770,&750,&730,&700,&000
Red:
Data &755,&744,&733,&722,&711,&711,&700,&600,&600,&500,&400,&400,&300,&300,&201,&000
Green:
Data &575,&474,&373,&272,&171,&070,&060,&060,&050,&040,&040,&030,&030,&020,&010,&000
Blue:
Data &557,&447,&337,&227,&117,&117,&007,&006,&006,&005,&004,&004,&003,&003,&002,&000
Rainbow:
Data &774,&772,&750,&630,&700,&704,&707,&507,&335,&017,&047,&065,&074,&063,&070,&000
Gosub Mark_menu
Return
Procedure Mark_menu
If Palette%=0
Menu 22,1 ! 1 puts a check by the menu item
Menu 23,0 ! 0 removes a check
Menu 24,0
Menu 25,0
Endif
If Palette%=1 Or Palette%=2 Or Palette%=3
Menu 22,0
Menu 23,0
Menu 24,1
Menu 25,0
Endif
If Palette%=4
Menu 22,0
Menu 23,1
Menu 24,0
Menu 25,0
Endif
If Palette%=7
Menu 22,0
Menu 23,0
Menu 24,0
Menu 25,1
Endif
Return
Procedure Defaults
Ixs=-0.75
Rrange=3.25
Iys=0
Climit%=100
Gosub Params
Return
Procedure Save_screen
Write #1,Ixs,Rrange,Iys,Climit% ! saves range values
Bput #1,Varptr(Screen1$),32000 ! saves the WHOLE screen to disk
Close #1
Return
Procedure Load_screen
Fractal!=True
Open "I",#1,Filename$
Input #1,Ixs,Rrange,Iys,Climit%
Bget #1,Varptr(Screen1$),32000
Close #1
Gosub Convert_params
Gosub Params
Return