Code: Select all
w,h = #.scrsize()
sfx = -2.5; sfy = -2*h/w; sfs = 4
#.aaoff()
:again
end,redo,update = 0
-> draw() 'render fractal in another thread
>
moved = 0
> #.pan() 'multitouch navigation
moved = 1
x,y,s = #.pan(3)
x -= (s-1)/2*w
y -= (s-1)/2*h
#.drawoff(x,y,s)
<
? moved 're-render
sfs /= s
sfx -= x*sfs/w
sfy -= y*sfs/w
again -> end
redo = 1
.
? update & !redo 'display render
update = 0
#.drawoff(0,0)
.
wn,hn = #.scrsize()
? wn!=w | hn!=h 'screen resize
w = wn; h = hn
again -> end
redo = 1
.
<
draw()=
:loop
#.offon() 'draw in offscreen buffer
#.scrclear(0,0,0)
.redo = 0
sfx = .sfx; sfy = .sfy; fs = .sfs/.w
> y, 1...h
> x, 1...w
fx = sfx + x*fs
fy = sfy + y*fs
#.drawpoint(x,y,color(fx,fy):3)
<
loop -> .redo
.update = 1
<
.end = 1
.
color(x,y)=
zr = x; zi = y; n = 0
maxn = #.int(200*(1-#.log10(.sfs/4)))
> zr*zr+zi*zi<4 & n<maxn
zrn = zr*zr-zi*zi+x; zin = 2*zr*zi+y
zr = zrn; zi = zin; n += 1
<
? n=maxn; <= 0,0,0; .
<= #.hsv2rgb(n/maxn*360,1,1):3
.