[Closed] mandelbrot fun
it is very slow and even useless, but maybe someone is iterested in this mandelbrot script.
i have adapted the code from here: http://gmc.yoyogames.com/index.php?showtopic=273433
if someone has an idea to make it faster, then do it !
greetings boris
pr = undefined
pt = undefined
iter = 0.0
zoomf = 1.0
moveX = -0.5
moveY = 0.0
maxIterations = 50
newRe = 0.0
newIm = 0.0
oldRe = 0.0
oldIm = 0.0
w = 300
h = 300
tmp_bmp = bitmap w h
col_arr = #()
disableSceneRedraw()
undo off
for xx = 1 to w do
(
col_arr = #()
for yy = 1 to h do
(
pr = 1.5 * (xx - w / 2.0) / (0.5 * zoomf * w) + moveX
pt = (yy - h / 2.0) / (0.5 * zoomf * h) + moveY
newRe = 0.0
newIm = 0.0
oldRe = 0.0
oldIm = 0.0
for i = 0 to maxIterations by 1 do
(
oldRe = newRe
oldIm = newIm
newRe = oldRe * oldRe - oldIm * oldIm + pr
newIm = 2.0 * oldRe * oldIm + pt
iter = i -- this is the iteration when exiting the loop
if((newRe * newRe + newIm * newIm) > 4) then exit
)
col = 256.0/maxIterations*iter -- create a color value based on iter
newcol = (color col col col)
append col_arr newcol
)
setpixels tmp_bmp [0,xx] col_arr
display tmp_bmp
)
enableSceneRedraw()
Wow, very cool I think the problem is the setpixels command, It´s very slow.
Using some .net to build the bitmap may speed thinks up.
Anyway, there´s more fun watching the image showing up not so fast
Unfortunately, .NET GDI+ in MAXScript (2D Drawing classes) is not so fast :sad:.
I have coded some scripts with it and for example just converting a MAXScript bitmap to a .NET one by copying the bitmap pixels takes a ‘long’ time…
But GDI+ is more poweful with high level methods to draw lines, circles, texts etc.
This is rather cool.
I played with the code a bit to see how fast it can be.
On my laptop, I’ve got it down from 23 seconds to 7 seconds for the same design by memory usage and code optimization. I intend to post a sort of a tutorial tomorrow to show you what can be done to speed things up. But it cannot be done much faster because the loop in a loop in a loop iterations take their time even if you don’t fill pixels…on my laptop I measured 6.8 seconds without writing to the bitmap. Unless you decide to reduce the quality (maxIterations) of the design or any other settings that affect the speed.
But there are definitely ways to make it faster. If you want, try to figure out what I did before I post the solution…
hi bobo
i guess wrapping the recursive loop into a function and doing a lot of gc() is what you ment.
i am very interested in your solution.
greetings boris
Nope,
I optimized the array memory management, the for loop exit (which, as the Help says, is slow and should be avoided), the bitmap update rate, took some calculations out of the loop to avoid redundant calculation of the same value, and took advantage of the fact this particular fractal design is simetrical vertically. This and the loop exit gave me the most speed increase.
I am a bit busy right now, but still plan to post the whole solution in the next days…