RetroBASIC

Retrogamecoding(.org) => Examples => Topic started by: Peter on November 20, 2012, 01:35:14 PM

Title: Mandel Utopia
Post by: Peter 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()
Title: Re: Mandel Utopia
Post by: Cybermonkey 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.
Title: Re: Mandel Utopia
Post by: Bereb 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 (http://lua-users.org/wiki/OptimisingUsingLocalVariables) 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. »
Title: Re: Mandel Utopia
Post by: Peter on November 20, 2012, 02:17:41 PM
Yes I know, I had forget it!
Title: Re: Mandel Utopia
Post by: Tomaaz 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. ;)