Re: Mandelbrot fractal maker
Posted: Thu Jul 21, 2011 10:38 pm
with what 3:?
Or if coroutines aren't your thing. simply use a thread.Jasoco wrote:And if creating the Fractal takes too long, with some work you could also make it so it will update and draw a progress bar while it is calculating by taking advantage of calling stuff like love.timer.step(), love.graphics.clear(), drawing your progress stuff to the screen and then love.graphics.present(). That might be more advanced, but when used properly it can be useful. It can be called inside any process that takes a while. You just don't want to call it every loop since it slows the thing down, instead you call that stuff every certain loops. Like every 10 or every 100. Since the loop works much faster than a normal frame does, you could go through a thousand loops in a few frames time. So you could even call it every 1000 iterations and still have a pretty good progress indication. And it doesn't have to be a bar, it can be a spinner or a simple message that says "Calculating! Please wait..."
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
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!TechnoCat wrote:Or if coroutines aren't your thing. simply use a thread.Jasoco wrote:And if creating the Fractal takes too long, with some work you could also make it so it will update and draw a progress bar while it is calculating by taking advantage of calling stuff like love.timer.step(), love.graphics.clear(), drawing your progress stuff to the screen and then love.graphics.present(). That might be more advanced, but when used properly it can be useful. It can be called inside any process that takes a while. You just don't want to call it every loop since it slows the thing down, instead you call that stuff every certain loops. Like every 10 or every 100. Since the loop works much faster than a normal frame does, you could go through a thousand loops in a few frames time. So you could even call it every 1000 iterations and still have a pretty good progress indication. And it doesn't have to be a bar, it can be a spinner or a simple message that says "Calculating! Please wait..."
multiplication ~= additionGijsB wrote:i tried changing the xmin,xmax,etc
but all it does random crap..
help 3:
this is what i have now =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
I said multiply, and you are adding.GijsB wrote:kraftman,
ur not making sense right now, explain please -__-