! MANDELBROT PROGRAM: Shows a "rough draft" of the M-set in blue.
! Then allows to click to select a c value and shows the orbit of the z=0 point for 20 iterations.
! It also prints the Xn, Yn values, and it indicates if the point c chosen is in the prisoner or escape (OUT!!!) sets.
!ITERATE in the complex plane : Zn+1 = Zn^2 + C,
!where Zn = Xn + i*Yn and is a complex variable, and
!Xn+1 = (Xn*Xn - Yn*Yn) + Creal,
!Yn+1 = 2*Xn*Yn + Cimag,
SET MODE "graphics"
ASK PIXELS hpix,vpix
LET ratio=hpix/vpix
SET WINDOW -2*ratio,2*ratio,-2,2
SET COLOR "GREEN"
BOX CIRCLE -2,2,-2,2
PLOT -2,0;2,0
PLOT 0,-2;0,2
SET COLOR "BLUE"
FOR j=-100 to 100
FOR k = -100 to 100
LET x = 0
LET y = 0
FOR n=1 to 20
LET x1 = x*x - y*y + j/50
LET y1 = 2*x*y + k/50
LET r2 = x1*x1 + y1*y1
IF r2>4 THEN EXIT FOR
LET x = x1
LET y = y1
NEXT n
IF n=21 THEN PLOT j/50,k/50
NEXT k
NEXT j
BOX KEEP -2,2,-2,2 IN MAND$
DO
CLEAR
SET COLOR "BLACK"
BOX SHOW MAND$ AT -2,-2
PRINT "CLICK TO SELECT A VALUE FOR c"
GET POINT cr,ci
LET x=0
LET y=0
PLOT 0,0;cr,ci
PRINT "cr=";cr,"ci=";ci
PRINT " x"," y"
PRINT 0,0
PRINT cr,ci
BOX DISK cr-.02,cr+.02,ci-.02,ci+.02
FOR n=1 to 30
LET x1 = x*x - y*y + cr
LET y1 = 2*x*y + ci
LET r2 = x1*x1 + y1*y1
IF r2>16 THEN EXIT FOR
LET x = x1
LET y = y1
PLOT x,y;
PRINT x,y
PAUSE.2
NEXT n
IF n<30 THEN
SET COLOR "RED"
BOX DISK cr-.02,cr+.02,ci-.02,ci+.02
PLOT TEXT, AT cr,ci:" OUT!!!"
END IF
PLOT
DO
GET MOUSE x,y,s
LOOP UNTIL s=2
LOOP
END