It works!!!!!!
This commit is contained in:
57
main.cpp
57
main.cpp
@@ -0,0 +1,57 @@
|
||||
#include "include/constants.hpp"
|
||||
#include "include/mandelbrot.hpp"
|
||||
#include <iostream>
|
||||
#include <raylib.h>
|
||||
|
||||
Color LerpColor(Color a, Color b, float t) {
|
||||
return {(unsigned char)(a.r + (b.r - a.r) * t),
|
||||
(unsigned char)(a.g + (b.g - a.g) * t),
|
||||
(unsigned char)(a.b + (b.b - a.b) * t), 255};
|
||||
}
|
||||
|
||||
void drawMandelbrot() {
|
||||
using namespace Constants;
|
||||
|
||||
double xNorm{};
|
||||
double yNorm{};
|
||||
double cReal{};
|
||||
double cImag{};
|
||||
|
||||
for (int x{}; x <= Constants::windowWidth; ++x) {
|
||||
for (int y{}; y <= Constants::windowHeight; ++y) {
|
||||
xNorm = x / static_cast<double>(Constants::windowWidth);
|
||||
yNorm = y / static_cast<double>(Constants::windowHeight);
|
||||
|
||||
cReal = negRealRange + xNorm * (posRealRange - negRealRange);
|
||||
cImag = negImagRange + yNorm * (posImagRange - negImagRange);
|
||||
|
||||
int iterationsMandelbrot{calculateMandelbrot(cReal, cImag)};
|
||||
|
||||
if (iterationsMandelbrot - 1 == maxIterations) {
|
||||
DrawPixel(x, y, BLACK);
|
||||
} else {
|
||||
float t = static_cast<float>(iterationsMandelbrot) / maxIterations;
|
||||
Color color = LerpColor(BLUE, RED, t);
|
||||
DrawPixel(x, y, color);
|
||||
}
|
||||
// std::cout << "Iterations: " << iterationsMandelbrot << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
InitWindow(Constants::windowWidth, Constants::windowHeight,
|
||||
"Mandelbrot Plot");
|
||||
SetTargetFPS(60);
|
||||
|
||||
while (!WindowShouldClose()) { // Runs until ESC or window close
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
drawMandelbrot();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user