#Need help rendering a Mandelbrot set

1 messages · Page 1 of 1 (latest)

rapid mango
#

Ive been recently really wanting to just render a mandelbrot set that i could later add functionality, but i cant figure out the details of the math on how to do it.

#

the code so far thanks to ppl in #programming

inland arrow
#
function check(cx, cy) {
    var _x = 0;
    var _y = 0;
    var x2 = _x*_x;
    var y2 = _y*_y;
    var iter = 0;
    
    while ((iter < max_iter) && ((x2 + y2) < 4.0))
    {
        _y = 2*_x*_y + cy;
        _x = x2 - y2 + cx;
        x2 = _x * _x;
        y2 = _y * _y;
        ++iter;
    }
    
    return iter < max_iter;
}
rapid mango
#

ty will do when i get home

rapid mango
#

hello

#

@inland arrow

#

very cool

inland arrow
#

Good to see you got it working. Presumably you know if you return the iter value instead of a boolean you can try to convert it to a color, to get some kind of shading.

#

The more you zoom in on the border the more colorful that approach gets.

rapid mango
#

ill go do some reasearch

#

probably

inland arrow
#

make_color_rgb(cells[i][j] mod 256, 0, 0) will give a red shade. make_color_hsv(cells[i][j] mod 256, 255, 255) will do something across a color spectrum. Use that in draw_set_color() for each point you draw.

rapid mango
#

ok

#

im gonna modify the code so itll place the colors value for each pixel rather than just 0 or 1

#

wait so

#

nvm

#

im not gonna do that ill just do the thing in the draw event

rapid mango
#

nvm

#

it works

inland arrow
#

Cool.

#

I basically meant put either iter in the cells or the color, but seems like you figured that out.

rapid mango
#

i basicallty just made it return the iterations if its not in the set

#

-1 means its in the set

inland arrow
#

If you want to eliminate the squash vertically, change the range of -1.25 to 1.25 by multiplying the cy value passed into the check() function by room_height/room_width.

rapid mango
#

also i was planning on something like a way to zoom with gui but it runs too slow for that

#

takes a good few seconds to render one frame and like 20 to actually generate it

inland arrow
#

There are tons of ways to speed up, but involves a lot of code.

rapid mango
#

yeah

#

i dont really wanna tho

inland arrow
#

I stopped a long time ago trying to make a fast mandelbrot after I used fractint.

#

I'm sure there are other tools these days, using shaders and whatnot (although the precision needed to zoom becomes a headache, but maybe some smart person worked around that too).

inland arrow
#

Regardless of whether you pursue it further, it is always fun to have done it at least once.

rapid mango
#

yes

#

although i kinda feel ashamed i didnt do it all myself but yno

inland arrow
#

Eh, your code was 95% there.

rapid mango
#

at this point its all just ur code

#

but either way its very cool to see it work