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: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:
Take a look at this:
http://www.wolframalpha.com/input/?i=x^ ... +-30%2C+30

ignore the equation, I'm just using it to draw a circle

look what happens when we scale the x and y ranges:

http://www.wolframalpha.com/input/?i=x^ ... +-20%2C+20

and when we translate the x range:

http://www.wolframalpha.com/input/?i=x^ ... +-20%2C+20

or the y range:

http://www.wolframalpha.com/input/?i=x^ ... +-15%2C+25
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

GOT IT :D

AND THANKS KRAFTMAN :D

Code: Select all


resolution = 4

size = 600
kt = 100
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/2
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+dx*10
      xmax = xmax+dx*10
      dx = (xmax-xmin)/size
      run()
   elseif k == "a" then
      xmin = xmin-dx*10
      xmax = xmax-dx*10
      dx = (xmax-xmin)/size
      run()
   elseif k == "s" then
      ymin = ymin+dy*10
      ymax = ymax+dy*10
      dy = (ymax-ymin)/size
      run()
   elseif k == "w" then
      ymin = ymin-dy*10
      ymax = ymax-dy*10
      dy = (ymax-ymin)/size   
      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:GOT IT :D

AND THANKS KRAFTMAN :D

Code: Select all


resolution = 4

size = 600
kt = 100
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/2
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+dx*10
      xmax = xmax+dx*10
      dx = (xmax-xmin)/size
      run()
   elseif k == "a" then
      xmin = xmin-dx*10
      xmax = xmax-dx*10
      dx = (xmax-xmin)/size
      run()
   elseif k == "s" then
      ymin = ymin+dy*10
      ymax = ymax+dy*10
      dy = (ymax-ymin)/size
      run()
   elseif k == "w" then
      ymin = ymin-dy*10
      ymax = ymax-dy*10
      dy = (ymax-ymin)/size   
      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

I give up. :'(
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

what?

IT WORKS

and i understand it know

when changing your look = you can change the x and the y, but the diffrence between max-min must keep the same.
when zooming in = you must smaller the x and y
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

GijsB wrote:what?

IT WORKS

and i understand it know

when changing your look = you can change the x and the y, but the diffrence between max-min must keep the same.
when zooming in = you must smaller the x and y
it doesnt zoom to the center of the current view.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

i already thought of that ;)

change xmax to -1.5 and xmin to 1.5

so when you mutliply, or divide, you get the same numbers as when dividing and mulitplying with y(because that was the problem; you got diffrent numbers)
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

That'll only work if you only zoom without panning.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

._.

i give up too now.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

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?)
Attachments
Mandelbrot.love
(919 Bytes) Downloaded 137 times
Last edited by GijsB on Sat Nov 03, 2012 12:39 pm, edited 1 time in total.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Mandelbrot fractal maker

Post by Roland_Yonaba »

GijsB wrote: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?)
Well, not yet.

Code: Select all

--line 86 throws an error, when pressing wheel down button
scaleymax = sizeymax+zoomspeed
main.lua: 86: attempt to perform arithmetic on global 'sizeymax' ( anil value)
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests