#include <generators/shipJuliaGen.hh> #include <complex> using std::complex; using std::clamp; using std::abs; namespace ty::gen { shipJuliaGen::shipJuliaGen(const int& w, const int& h) : fracGen(w, h) { settings.push_back({"jr", juliaReal}); settings.push_back({"ji", juliaImaginary}); } shipJuliaGen::~shipJuliaGen() { } void shipJuliaGen::runGen(vector<unsigned char>& image) { maxIter = clamp(maxIter, iterMinLimit, iterMaxLimit); auto [xRange, yRange] = scaleRange(); double xMin = realCenter - xRange; double xMax = realCenter + xRange; double yMin = imagCenter - yRange; double yMax = imagCenter + yRange; double scaleX = (xMax - xMin) / width; double scaleY = (yMax - yMin) / height; complex<double> c(juliaReal, juliaImaginary); for (int py = 0; py < height; ++py) { #pragma omp parallel for schedule(dynamic, 16) for (int px = 0; px < width; ++px) { double real = xMin + static_cast<double>(px) * scaleX; double imag = yMin + static_cast<double>(py) * scaleY; complex<double> z(real, imag); int iteration = 0; for (; abs(z) <= 2.0 && iteration < maxIter; ++iteration) { z = complex<double>(abs(z.real()), abs(z.imag())); z = z * z + c; } unsigned char r = 0, g = 0, b = 0; if (iteration < maxIter) { double t = static_cast<double>(iteration) / maxIter; r = static_cast<unsigned char>(9 * (1 - t) * t * t * t * 255); g = static_cast<unsigned char>(15 * (1 - t) * (1 - t) * t * t * 255); b = static_cast<unsigned char>(8.5 * (1 - t) * (1 - t) * (1 - t) * t * 255); } int idx = (py * width + px) * 4; image[idx] = r; image[idx + 1] = g; image[idx + 2] = b; image[idx + 3] = 255; } } } } // ty::gen