Fractal browser

Post Reply
User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Fractal browser

Post by Mr. Kibernetik »

This program is for Mandelbrot fractal exploration, with multitouch fractal navigation.

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
.
Снимок1.PNG
Снимок1.PNG (43.31 KiB) Viewed 2558 times
Снимок2.PNG
Снимок2.PNG (228.14 KiB) Viewed 2558 times
Снимок3.PNG
Снимок3.PNG (359.04 KiB) Viewed 2558 times
Снимок4.PNG
Снимок4.PNG (212.36 KiB) Viewed 2558 times

Post Reply