Retrogamecoding(.org) > Examples

Mandel Utopia

(1/1)

Peter:
Hi,

A little bit Mandelbrot RIP

--- Code: ---screen(600,430,0,"Mandel Utopia")

local i,x,y,zx,zy,cx,cy,tmp,miter,zm =0,0,0,0,0,0,0,0,570,150
color(255,255,255)
drawtext(100,32,"WAIT....")
redraw()

for y=0,screenheight()+80 do
  for x=0, screenwidth()+50 do
    zx=0
    zy=0
    cx= (x-400)/zm
    cy= (y-300)/zm
    i = miter
  while zx*zx+zy*zy <4 and i >0 do
    tmp = zx * zx - zy * zy + cx
    zy = 2 * zx * zy + cy
    zx = tmp
    i=i-1
  end
  color(i*12,i*7,i*3)
  dot(x-50,y-80)
  end
end
redraw()
inkey()
closewindow()

--- End code ---

Cybermonkey:
Nice, but using the fast trick like this:

--- Code: ---local i,x,y,zx,zy,cx,cy,tmp,miter,zm =0,0,0,0,0,0,0,0,570,150
--- End code ---
It's a lot of faster.

Bereb:

--- Quote from: Cybermonkey on November 20, 2012, 01:58:37 PM ---Nice, but using the fast trick (...)
It's a lot of faster.

--- End quote ---
Yes, waiting is almost 6 times less long  :)
HERE is the explanation, for those who are interested:
« Local variables are very fast as they reside in virtual machine registers, and are accessed directly by index. Global variables on the other hand, reside in a lua table and as such are accessed by a hash lookup. »

Peter:
Yes I know, I had forget it!

Tomaaz:
As there is no zooming you can use less number of iterations. Just change a value of miter variable. Everything above 50 should work fine. Here is example with 64 iterations:


--- Code: ---screen(600,430,0,"Mandel Utopia")

local i,x,y,zx,zy,cx,cy,tmp,miter,zm =0,0,0,0,0,0,0,0,64,150
color(255,255,255)
drawtext(100,32,"WAIT....")
redraw()

for y=0,screenheight()+80 do
  for x=0, screenwidth()+50 do
    zx=0
    zy=0
    cx= (x-400)/zm
    cy= (y-300)/zm
    i = miter
  while zx*zx+zy*zy <4 and i >0 do
    tmp = zx * zx - zy * zy + cx
    zy = 2 * zx * zy + cy
    zx = tmp
    i=i-1
  end
  color(i*12,i*7,i*3)
  dot(x-50,y-80)
  end
end
redraw()
inkey()
closewindow()

--- End code ---

Still looks nice and works much faster. ;)

Navigation

[0] Message Index

Go to full version