Author Topic: Mandel Utopia  (Read 2695 times)

Peter

  • Guest
Mandel Utopia
« on: November 20, 2012, 01:35:14 PM »
Hi,

A little bit Mandelbrot RIP
Code: [Select]
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()
« Last Edit: November 20, 2012, 02:16:35 PM by Peter »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Mandel Utopia
« Reply #1 on: November 20, 2012, 01:58:37 PM »
Nice, but using the fast trick like this:
Code: [Select]
local i,x,y,zx,zy,cx,cy,tmp,miter,zm =0,0,0,0,0,0,0,0,570,150It's a lot of faster.

Bereb

  • Guest
Re: Mandel Utopia
« Reply #2 on: November 20, 2012, 02:14:08 PM »
Nice, but using the fast trick (...)
It's a lot of faster.
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. »
« Last Edit: November 20, 2012, 04:19:31 PM by Bereb »

Peter

  • Guest
Re: Mandel Utopia
« Reply #3 on: November 20, 2012, 02:17:41 PM »
Yes I know, I had forget it!

Tomaaz

  • Guest
Re: Mandel Utopia
« Reply #4 on: November 20, 2012, 11:19:46 PM »
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: [Select]
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()

Still looks nice and works much faster. ;)
« Last Edit: November 21, 2012, 12:45:23 AM by Tomaaz »