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:whats the diffrence?!
your in both ways making the numbers bigger/smaller
and even when i do that, it WONT work.
There's a big difference.

Currently, you are plotting onto a cartesian plane between 1.5 and 0.3 in the x, and -1.5 and 1.5 in the y. You are splitting this grid based on the size, and checking each point to see if it matches the criteria.

if you multiply 1.5 and -0.3 by 0.9 you get 1.35 and -0.27, so the mesh is finer, and slightly more zoomed in.
if you add and subtract 0.9 respectively, in the x plane you get 2.4 and -1.2, which results in zooming out by quite a large degree in the x plane. In the y plane, you end up zooming in.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

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

Re: Mandelbrot fractal maker

Post by GijsB »

then why is this too not working :

Code: Select all


resolution =2

size = 100
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()
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 == "right" then
		xmin = xmin*0.9
		xmax = xmax*0.9
		ymin = ymin*0.9
		ymax = ymax*0.9	
	elseif k == "left" then
		xmin = xmin/0.9
		xmax = xmax/0.9
		ymin = ymin/0.9
		ymax = ymax/0.9	
	end
	run()
end
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

In other words, the difference is which numbers you make bigger/smaller, and by how much.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Mandelbrot fractal maker

Post by kraftman »

GijsB wrote:then why is this too not working :

Code: Select all


resolution =2

size = 100
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()
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 == "right" then
		xmin = xmin*0.9
		xmax = xmax*0.9
		ymin = ymin*0.9
		ymax = ymax*0.9	
	elseif k == "left" then
		xmin = xmin/0.9
		xmax = xmax/0.9
		ymin = ymin/0.9
		ymax = ymax/0.9	
	end
	run()
end
because 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 »

i now have this but when you go up or down, and then zoom in/out it makes the ymax and ymin randomly smaller/bigger >_<

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
TechnoCat
Inner party member
Posts: 1612
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Mandelbrot fractal maker

Post by TechnoCat »

Jasoco wrote:Simply? Aren't threads a lot harder to figure out how to code? I know I've never known how to use them. Tell me how!
Haha, yes. Simply.
Attachments
threaded_mandel.love
0.7.2
(931 Bytes) Downloaded 144 times
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Mandelbrot fractal maker

Post by GijsB »

wow what are you guys doing to my code 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:i now have this but when you go up or down, and then zoom in/out it makes the ymax and ymin randomly smaller/bigger >_<

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

Because 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 »

when you update those when changing your look from left to right, up and down you change the size of the mandelbrot!
dx and dy must only be updated when zooming!!

thanks for all of your help kraftman!
Last edited by GijsB on Fri Jul 22, 2011 12:49 pm, edited 3 times in total.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests