/* ======================================================================== * * Filename: main.cpp * Description: simple c++ renderer * Author: Diego A. Estrada Rivera * Version: 0.0.1 * * ======================================================================== */ #include #include #include #include "utils.hpp" fn main() -> int { static var c = Canvas<1000, 1000>(Point(0.0, 0.0), 3.0); static let histogram = [] { var ret = std::array(); let begin = Color(182, 0.00, 0.0); let end = Color(1.0, 1.00, 1.0); var t = 1; for (var &c : ret) c = begin.lerp(end, (double)t / 255.0), ++t; return ret; }(); [[maybe_unused]] let mandelbrot = [](Point coordinate) { let max_iteration = 20000ul; var x = 0.0L; var y = 0.0L; var x_squared = 0.0L; var y_squared = 0.0L; var iteration = 0u; while (std::islessequal((x_squared + y_squared), 4) && (iteration < max_iteration)) { y = fma(2 * x, y, coordinate.y); x = x_squared - y_squared + coordinate.x; x_squared = x * x; y_squared = y * y; iteration++; } return Color(iteration); }; [[maybe_unused]] let julia = [](Point z) { let R = 4.0; var iteration = 0u; let max_iteration = 1000u; let c = Point(-0.6, 0.8); while (z.x * z.x + z.y * z.y < R * R && iteration < max_iteration) { auto xtemp = z.x * z.x - z.y * z.y; z.y = 2 * z.x * z.y + c.y; z.x = xtemp + c.x; ++iteration; } return histogram[iteration & 0xFF]; }; [[maybe_unused]] let newton = [](Point z) { let f = [](Point z){ return Point(z.x * z.x * z.x, - 1); }; let dx = [](Point z){ (void)z; }; (void)z; (void)f; (void)dx; return Color(0.0, 0.0, 0.0); }; ignore = c.construct(mandelbrot); if (not c.save_to_ppm("tmp.ppm")) std::cout << "Could not output to tmp.ppm\n"; return 0; }