Mandelbrot fractal maker

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

GijsB wrote:Thanks for all of your help Kraftman!!

My pleasure.
Good night.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

oh god i cant fix it, this is what i have now =

Code: Select all

resolution =2

size = 300
kt = 50
m = 4.0
xmin = 2.1
xmax = -0.6
ymin = -1.5
ymax = 1.5
dx = (xmax-xmin)/size
dy = (ymax-ymin)/size
pixels = {}
function run()
pixels = {}
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
end
run()
function love.draw()
	for i,v in pairs(pixels) do
		love.graphics.setColor( -v.C, -v.C, -v.C, 255 )
		love.graphics.rectangle("fill",v.X,v.Y,resolution,resolution)
	end
end
function love.keypressed(k)
	if k == "d" then
		xmin = xmin*0.9
		xmax = xmax*0.9
		run()
	elseif k == "a" then
		xmin = xmin/0.9
		xmax = xmax/0.9
		run()
	elseif k == "s" then
		ymin = ymin*0.9
		ymax = ymax*0.9
		run()
	elseif k == "w" then
		ymin = ymin/0.9
		ymax = ymax/0.9		
		run()
	elseif k == "q" then
		xmin = xmin*0.9
		xmax = xmax*0.9
		ymin = ymin*0.9
		ymax = ymax*0.9
		dx = (xmax-xmin)/size
		dy = (ymax-ymin)/size
		run()
	elseif k == "e" then
		xmin = xmin/0.9
		xmax = xmax/0.9
		ymin = ymin/0.9
		ymax = ymax/0.9		
		dx = (xmax-xmin)/size
		dy = (ymax-ymin)/size
		run()
	end
end
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

GijsB wrote:oh god i cant fix it, this is what i have now =

Code: Select all

resolution =2

size = 300
kt = 50
m = 4.0
xmin = 2.1
xmax = -0.6
ymin = -1.5
ymax = 1.5
dx = (xmax-xmin)/size
dy = (ymax-ymin)/size
pixels = {}
function run()
pixels = {}
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
end
run()
function love.draw()
	for i,v in pairs(pixels) do
		love.graphics.setColor( -v.C, -v.C, -v.C, 255 )
		love.graphics.rectangle("fill",v.X,v.Y,resolution,resolution)
	end
end
function love.keypressed(k)
	if k == "d" then
		xmin = xmin*0.9
		xmax = xmax*0.9
		run()
	elseif k == "a" then
		xmin = xmin/0.9
		xmax = xmax/0.9
		run()
	elseif k == "s" then
		ymin = ymin*0.9
		ymax = ymax*0.9
		run()
	elseif k == "w" then
		ymin = ymin/0.9
		ymax = ymax/0.9		
		run()
	elseif k == "q" then
		xmin = xmin*0.9
		xmax = xmax*0.9
		ymin = ymin*0.9
		ymax = ymax*0.9
		dx = (xmax-xmin)/size
		dy = (ymax-ymin)/size
		run()
	elseif k == "e" then
		xmin = xmin/0.9
		xmax = xmax/0.9
		ymin = ymin/0.9
		ymax = ymax/0.9		
		dx = (xmax-xmin)/size
		dy = (ymax-ymin)/size
		run()
	end
end
you forgot to update dx and dy
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

kraftman, thanks but no,

when you update the dx and dy when changing your look from left to right, up and down, you change the size of the mandelbrot, not the look, test it out yourself
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

GijsB wrote:kraftman, thanks but no,

when you update the dx and dy when changing your look from left to right, up and down, you change the size of the mandelbrot, not the look, test it out yourself
That's my point. It's only because you aren't adding the dx and dy that you can't see that what you are doing is wrong.

Changing the xmax part of your code:

Code: Select all

xmin = xmin*0.9
xmax = xmax*0.9
run()
does nothing at all, since xmax is not used in run(). The only reason it appears to do what you intended is that jx is based on xmin, and xmin is changed.

However, once you try and zoom in or out, the new and incorrect xmax is used to calculate a new dx, which in turn is wrong.

Simply put:
If you wish to move about across the graph, you need to increase xmax and xmin by the same amounts.
If you wish to zoom into the graph, you need to increment xmax and xmin by opposite amounts.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

but how do i move up and down then 3:?

( or i dont understand you again, sorry :( )

Edit = oh my god i just cant get it to work and i still dont understand what i do wrong :(, can you just please make the piece of code for me and explain for everything why =3?
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

GijsB wrote:but how do i move up and down then 3:?

( or i dont understand you again, sorry :( )

ok, lets say we draw a graph, and its axis go from x = 0 to x = 10, and from y = 0 to y = 10.

if we have a line from x = 3, y = 3 to x = 7, y = 7 then it will draw a diagonal across the middle of the graph.

If we want to make the lien appear to move, without changing its coordinates, we can simpyl redraw the graph, with axis from x = 3 to x = 13, y = 3, y = 13.
If the graph remains the same size, the line will appear to have moved 3 points to the left, and 2 down.

If we wanted to make the line larger, we could change the axis to x = 3 to x = 7, y = 3 to y = 7, Which would make the diagonal appear to go from one corner of the graph to the other.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

oh my god..

i feeling dumb,

because i still dont understand ):

can you please make it(i know its bad), and just explain every line ):?
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

If you explain this line

Code: Select all

 if tx*tx+ty*ty<=m and k<kt then 
I'll re-write the whole thing for you and comment every single line.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

is has to do with the C and Z number thingys(search it up) and the amount of iritations.

and i have writen this code a long loonng time ago

and i dont even want to try to understand it again, atleast THAT part 3:
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests