41#include "ramCanvas.hpp"
44const int CSIZE = 2048;
45const int MAXITR = 2048;
46const double BALL = 100;
49double theValues[CSIZE][CSIZE];
51double ranges[5][4] = { { -2.0, 1.0, -1.5, 1.5 },
52 { -0.12, -0.03, -0.92, -0.81 },
53 { 0.0353469, 0.5353469, 0.1153845, 0.6153845 },
54 { -1.5, -1.0, -0.5, 0.0 },
55 { 0.0353469, 0.5353469, 0.1153845, 0.6153845 }
59enum class whyStop { OUTSET,
66 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
67 mjr::ramCanvas3c8b potRamCanvas(CSIZE, CSIZE), distRamCanvas(CSIZE, CSIZE);
68 mjr::ramCanvas3c8b::colorType theColor;
69 double lightHeight = 1.125;
70 double lightAngle = std::numbers::pi/4;
71 std::complex<double> lightDirection = exp(lightAngle*std::complex<double>(0,1));
74 for(
int i=0; i<3; i++) {
76 potRamCanvas.newRealCoords(ranges[i][0], ranges[i][1], ranges[i][2], ranges[i][3]);
77 potRamCanvas.clrCanvasToBlack();
79 std::complex<double> z;
80 for(
int y=0;y<potRamCanvas.getNumPixY();y++) {
82 std::cout <<
" CASE: " << i <<
" LINE: " << y <<
"/" << CSIZE << std::endl;
83 for(
int x=0;x<potRamCanvas.getNumPixX();x++) {
85 double cr = potRamCanvas.int2realX(x);
86 double ci = potRamCanvas.int2realY(y);
87 std::complex<double> c(cr, ci);
88 std::complex<double> dc = 1.0;
89 std::complex<double> pder = dc;
90 std::complex<double> dder1 = 1.0;
91 std::complex<double> dder2 = 0.0;
92 double p = std::abs(c-0.25);
93 if((cr >= p-2.0*p*p+0.25) && std::abs(c+1.0) >= 0.25) {
95 for(count=0; ; count++) {
97 why = whyStop::MAXCOUNT;
100 if(std::abs(z)>BALL) {
101 why = whyStop::OUTSET;
104 dder2 = 2.0 * (dder2 * z + dder1 * dder1);
105 dder1 = 2.0 * dder1 * z + 1.0;
106 pder = pder * 2.0 * z + dc;
110 why = whyStop::INSET;
113 if(why == whyStop::OUTSET) {
114 if(std::abs(pder) < 0.00001) {
115 potRamCanvas.drawPoint(x, y,
"blue");
117 if(std::abs(z) < 0.00001) {
118 potRamCanvas.drawPoint(x, y,
"green");
120 std::complex<double> potNormal = z/pder;
121 potNormal = potNormal/std::abs(potNormal);
122 double potShade = std::real(potNormal * std::conj(lightDirection)) + lightHeight;
123 potShade = mjr::math::ivl::unit_clamp(potShade/(1+lightHeight));
124 potRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType(
static_cast<mjr::ramCanvas3c8b::colorChanType
>(mjr::math::linm::scl_real_to_int(potShade, 255)),
125 static_cast<mjr::ramCanvas3c8b::colorChanType
>(mjr::math::linm::scl_real_to_int(potShade, 255)),
126 static_cast<mjr::ramCanvas3c8b::colorChanType
>(mjr::math::linm::scl_real_to_int(potShade, 255))));
130 potRamCanvas.drawPoint(x, y,
"red");
133 if(why == whyStop::OUTSET) {
134 double zLogMod = 0.5*std::log(std::norm(z));
135 std::complex<double> distNormal = z*dder1*((1.0+zLogMod)*std::conj(dder1*dder1)-zLogMod*std::conj(z*dder2));
136 double distNormalAbs = std::abs(distNormal);
137 if(distNormalAbs < 0.00001) {
138 distRamCanvas.drawPoint(x, y,
"blue");
140 distNormal = distNormal/distNormalAbs;
141 double distShade = std::real(distNormal * std::conj(lightDirection)) + lightHeight;
142 distShade = mjr::math::ivl::unit_clamp(distShade/(1+lightHeight));
143 distRamCanvas.drawPoint(x, y, mjr::color3c8b::csCCdiag01::c(
static_cast<mjr::ramCanvas3c8b::csIntType
>(mjr::math::linm::scl_real_to_int(distShade, 255))));
146 distRamCanvas.drawPoint(x, y,
"red");
151 potRamCanvas.writeTIFFfile(
"mandelbrot_emboss_pot_" + std::to_string(i) +
".tiff");
152 distRamCanvas.writeTIFFfile(
"mandelbrot_emboss_dist_" + std::to_string(i) +
".tiff");
154 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
155 std::cout <<
"Total Runtime " << runTime.count() <<
" sec" << std::endl;
int main(int argc, char *argv[])