aUCBLogo Demos and Tests / mandel
to mandel [cmin -2-1.2i][cmax 0.7+1.2i]
if Key? [c=readChar if c==char 27 [stop]]
t=timefine
cs ht pu
sx=800
sy=600
sxh=sx/2
syh=sy/2
maxiter=500
col=array maxiter
repeat maxiter
[ n=repcount
col.n=hsb n*360/maxiter 1 1
]
col.maxiter=0
fx=1/(sx-1)*real cmax-cmin
fy=1/(sy-1)*imag cmax-cmin
for [ry 1 sy]
[ y=cmin+1i*(ry-1)*fy
z0=0i+0
repeat sx
[ rx=repcount
c=(rx-1)*fx+y
z=z0
; n=mandelIterateLogo z c maxiter
n=mandelIterate z c maxiter
setpixel list rx-sxh ry-syh col.n
]
if (Int mod ry 16)==0 [updateGraph]
if KeyP [ry=sy]
]
(pr timefine-t "seconds)
stopping=false
c1=mouseSelectC if stopping [stop]
c2=mouseSelectC if stopping [stop]
if Key? [c=readChar if c == char 27 [stop]]
(mandel c1 c2)
end
to mouseSelectC
pr [Use the mouse for selection of a coordinate!]
pr pi+pi*1i
overwriteMode
updateGraph
while [mousebuttons==0]
[ x=(mousex-1+sxh)*fx
y=(mousey-1+syh)*fy
c=cmin+x+1i*y
setCursor list first cursor (last cursor)-1
pr c
if Key?
[ c=readChar
if c == char 27
[ insertMode
stopping=true
output 0
]
]
wait 2
dispatchMessages
]
(pr)
until [MouseButtons==0]
[ setCursor list first cursor (last cursor)-1
pr repcount
dispatchMessages
]
insertMode
output c
end
to mandelIterateLogo z c maxiter
repeat maxiter ; compute orbit
[ z=z*z+c
if z > 4 [output repcount]
]
output maxiter
end