' *****************************************************************************
' **                             Mandelbrot Fractals                         **
' **                                   in                                    **
' **                                GFA Basic                                **
' **                                   by                                    **
' **                             Stephen Lovejoy                             **
' **                              Portland, Or                               **
' *****************************************************************************
' Based on ST Basic Program in "Atari ST Graphics & Sound"
' by J. Walkowiak   Published by Abacus Software
' In ST Basic Just one of these guys will take 8-12 hours to complete
' in UNcompiled GFA time is 1/2-3 hours (depending on Calculation depth)
Infinity=10000000   ! Ceiling on Calculations.
Cls     ! Clear the Screen
Gosub Scrn_size
Print Tab((Wide/2)-17);"BASIC Fractal--   Julia/Mandelbrot "
For X=1 To Wide   ! Simple loop for text. Makes it easier for Med/Low res. convertions
  Print "=";
Next X
Print "Calculation depth "
Input "[ex 10..99]";Calcdepth  ! Higher number gives nicer picture,but takes much longer
Print "Character depth "
Input "[ex 1..33]";Chardepth   ! See last note
Print "Remin "
Input "[ex. -0.75  0.0   1.1   0.14]";Remin    ! Real number minimum
Print "Remax "
Input "[ex.  2.25  0.2   1.27  0.18]";Remax    ! Real number Maximum
Print "Immin"
Input "[ex. -1.2  -1.06 -0.35 -1.05]";Immin    ! Imaginary Minimum
Print "Immax "
Input "[ex.  1.2  -0.9  -0.25 -0.25]";Immax    ! Imaginary Maximum
Alert 1,"This is going to tie|Things up for a long time!",2,"Ack!|[Alright!]",B
If B=1 Then
  End
Endif
Cls
Dreal=(Remax-Remin)/(Xwidth-1)
Ddimag=(Immax-Immin)/(Height-1)
For Iimag=0 To Height         ! Main body of program
  For Ireal=0 To Xwidth
    Lreal=Remin+Ireal*Dreal
    Limag=Immin+Iimag*Ddimag
    Re=Lreal
    Im=Limag
    Depth=0
    Gosub Recalc
    Gosub Sub
  Next Ireal
Next Iimag
Repeat   ! This loop keeps a Picture on screen until you press a key
Until Inkey$<>""
End
Procedure Scrn_size   ! Is it medium or Low resolution?
  If Xbios(4)=0 Then  !Low resolution
    Xwidth=320
    Height=200
    Wide=40
    Numcol=16
  Endif
  If Xbios(4)=1 Then   ! Medium Resolution
    Xwidth=640
    Height=200
    Wide=80
    Numcol=4
  Endif
  If Xbios(4)<>0 And Xbios(4)<>1 Then   ! High Resolution?!
    Alert 1,"Sorry, this is for|color monitors only!",1,"[OK]",B
    End    ! Life is tough, ain't it?
  Endif
Return
Procedure Recalc   ! Where all the local squares hang out
  Repeat
    Xx=Re*Re
    Yy=Im*Im
    Im=2*Re*Im-Limag
    Re=Xx-Yy-Lreal
    Inc Depth
  Until ((Depth=Calcdepth) Or ((Xx+Yy)>Infinity))
Return
Procedure Sub     !  To plot, or not to plot, that is the subroutine.
  If (Depth<Calcdepth) Then
    Gosub Plotting
  Endif
Return
Procedure Plotting    ! Draw a dot
  If (Depth>Chardepth) Then
    Color (Depth Mod Numcol)  ! in your favourite colour
    Plot Ireal,Iimag
  Else
    Gosub Rte350
  Endif
Return
Procedure Rte350    !Draw a different dot
  If (Depth Mod 2) Then
    Color (Depth Mod Numcol)   ! in a color you may not like, or no colour at all
    Plot Ireal,Iimag
  Endif
Return
