Hey guys! I have been fascinated by the mandelbrot and other fractals for a while now, but I never expected the maths behind them to be so simple. Anyway, i tried programming the mandelbrot, but apparently it is not quite as simple as I thought:
Code:
int xPix = 0, yPix = 0;
float x0, y0 ,x, y, x2, y2;
int iteration;
int max_iteration = 10;
for(xPix = 0; xPix < 800; xPix++)
{
for(yPix = 0; yPix < 600; yPix++)
{
x0 = xPix / 228.5714f - 2.5f;
y0 = yPix / 300 -1.0f;
x = x0;
y = y0;
x2 = x*x;
y2 = y*y;
iteration = 0;
while (x2 + y2 < 4 && iteration < max_iteration)
{
y = 2*x*y + y0;
x = x2 - y2 + x0;
x2 = x*x;
y2 = y*y;
iteration++;
}
if(iteration <= 0)
{
mandelbrot.SetPixel(xPix, yPix, sf::Color(0,0,0));
}
else
{
mandelbrot.SetPixel(xPix, yPix, sf::Color(255*sin((float)iteration), 255*cos((float)iteration), 255*-sin((float)iteration)));
}
}
}
This is what I get, I call it the Mandelnot:

I have tweeked so many things, that I am sure I have done something fundamentally wrong. I just don't know where. If anyone can help me I would be quite happy!