Page 1 of 6

Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 1:47 pm
by GijsB
Edit :

I now know what was wrong with the code and what was wrong with the scaling and moving and zooming etc..

so finnaly :

(move with 'wasd', zoom in and out with mousewheel, increase iterations with and 'u' and 'j' and increase size with 'y' and 'h')
(improvements ideas?)

oh and OpenGL version : http://glsl.heroku.com/e#4645.2

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 1:52 pm
by kikito
Can't MainCalculation be defined once, outside of the loops? Adding parameters, I suppose.

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 1:57 pm
by Robin
And it may also not be wise to put that code in love.draw. Instead, use Framebuffers. (Just ask if you need help figuring out how they work. :))

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 2:28 pm
by GijsB
i understand where those framebuffers are for, but i dont know how to use them 3:

anyway, i speeded up the code :

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 4:02 pm
by Robin
You are on the right track.

Look at this:

Code: Select all

function MainCalculation(jx, jy, wx, wy, k)
	local tx = wx*wx-(wy*wy+jx)
	local ty = 2.0*wx*wy+jy
	if tx*tx+ty*ty<=m and k<kt then 
		return MainCalculation(jx, jy, tx, ty, k + 1)
	end
	return k
end

for x = 0,size,resolution do
	local jx = xmin+x*dx
	for y = 0,size,resolution do
		local jy = ymin+y*dy
		table.insert(pixels,{X = x, Y = y, C = MainCalculation(jx, jy, 0, 0, 0)})
	end
end
Do you understand what changes I made?

I'll explain Framebuffers if you are ready for it and can't figure it out on your own (but I think you can).

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 4:18 pm
by tentus
GijsB wrote:i understand where those framebuffers are for, but i dont know how to use them 3:

anyway, i speeded up the code :
Note that framebuffers are not universally supported (about 81% of us support them, according to this source). I would recommend avoiding them unless you need them, since coding a graceful degradation essentially means twice the work, if not more, for a benefit that about a fifth of the community can never see.

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 4:34 pm
by GijsB
Robin, yes and there awesome :D

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 10:26 pm
by kraftman
Very cool (runs much quicker in LoveJIT btw)

Spent a while reading up on it and playing with the code/colours
test1.png
test1.png (108.88 KiB) Viewed 9383 times
Also found this which is quite cool:

http://www.youtube.com/watch?v=P3WdnLSI2hs

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 10:29 pm
by GijsB
But does anybody know how to zoom into it xD?

Re: Mandelbrot fractal maker

Posted: Thu Jul 21, 2011 10:32 pm
by kraftman
GijsB wrote:But does anybody know how to zoom into it xD?
change xmin/xmax ymin/ymax