/* Include libraries */ #include /* Include header files */ #include "fractData.hh" #include "genf.hh" #include "mansdl.hh" void genf::mandelbrot3(SDL_Renderer* renderer, fractData* fd) { constexpr double max = 2.25; constexpr double min = -2.25; for(unsigned int x = 0; x < fd->width; ++x) for(unsigned int y = 0; y < fd->height; ++y) { long double r = x * ((max + fd->real * fd->zoom) / fd->zoom - (min + fd->real * fd->zoom) / fd->zoom) / fd->width + (min + fd->real * fd->zoom) / fd->zoom; long double i = y * ((max + fd->imag * fd->zoom) / fd->zoom - (min + fd->imag * fd->zoom) / fd->zoom) / fd->width + (min + fd->imag * fd->zoom) / fd->zoom; long double r2 = 0.0; long double i2 = 0.0; unsigned int iter; for(iter = 0; iter < fd->maxIter; ++iter) { if(r2 * r2 + i2 * i2 >= 4.0) break; long double r2Temp = r2 * r2 * r2 - 3.0 * r2 * i2 * i2 + r; long double i2Temp = 3.0 * r2 * r2 * i2 - i2 * i2 * i2 + i; if(r2 == r2Temp && i2 == i2Temp) { iter = fd->maxIter; break; } r2 = r2Temp; i2 = i2Temp; } unsigned short int red = 0; unsigned short int green = 0; unsigned short int blue = 0; if(iter != fd->maxIter) { double t = (double)(iter) / (double)(fd->maxIter); red = (int)(9.0 * (1.0 - t) * t * t * t * 255.0); green = (int)(15.0 * (1.0 - t) * (1.0 - t) * t * t * 255.0); blue = (int)(8.5 * (1.0 - t) * (1.0 - t) * (1.0 - t) * t * 255.0); } SDL_SetRenderDrawColor(renderer, red, green, blue, SDL_ALPHA_OPAQUE); SDL_RenderDrawPoint(renderer, x, y); } }