http://www.ibly31.com/Stuff/thankyouthreeve.png
But its black and white. The wikipedia page says to graph each color depending on the number of iterations it took to reach. But right now its only taking 1 iteration or infinity. I'll post some code, hopefully you can spot what I'm doing wrong. Thanks!
EDIT: Infinity as in taking the max_iterations and exiting the loop due to the fact that it is taking too long to compute one pixel. If any of you know why it has to scale from -2.5 to 1, and -1 to 1, please explain! Thanks
Code: Select all
sf::Color ColorForPointOnFractal(float xx, float yy){
float x0 = ((xx * 3.5) / SCREENWIDTH ) - 2.5;
float y0 = ((yy * 2) / SCREENHEIGHT) - 1;
// these first two lines take the XX and YY values (0-1440, 0-900 respectively) and fit them into a scale of -2.5 to 1, and -1 to 1 respectively. The wikipedia's psuedocode section told //me to do this, i don't really understand why though.
float x = 0;
float y = 0;
unsigned int iteration = 0;
unsigned int max_iteration = 1000;
while(x*x + y*y <= 4 && iteration < max_iteration){
float xtemp = x*x - y*y + x0;
y = 2*x*y + y0;
x = xtemp;
iteration++;
}
if(iteration == max_iteration)
return sf::Color(125, 125, 125);
else
return sf::Color(255, 255, 255);
//return sf::Color(iteration / max_iteration * 255, iteration / max_iteration * 255, iteration / max_iteration * 255);
// this commented out line basically warps the iteration number from a scale from 1-255 resulting in a grayscale value for the color.
}
void CalculateFractal(){
for(int x = 0; x < SCREENWIDTH; x++){
for(int y = 0; y < SCREENHEIGHT; y++){
Fractal.SetPixel(x, y, ColorForPointOnFractal((float)x, (float)y));
}
}
}