Added Panning
This commit is contained in:
@@ -2,10 +2,7 @@
|
||||
|
||||
namespace Constants {
|
||||
constexpr int maxIterations{2000};
|
||||
constexpr int windowWidth{600};
|
||||
constexpr int windowHeight{600};
|
||||
constexpr double posRealRange{1.0};
|
||||
constexpr double negRealRange{-2.5};
|
||||
constexpr double posImagRange{1.25};
|
||||
constexpr double negImagRange{-1.25};
|
||||
constexpr int windowWidth{900};
|
||||
constexpr int windowHeight{900};
|
||||
|
||||
} // Namespace Constants
|
||||
|
||||
69
main.cpp
69
main.cpp
@@ -9,7 +9,8 @@ Color LerpColor(Color a, Color b, float t) {
|
||||
(unsigned char)(a.b + (b.b - a.b) * t), 255};
|
||||
}
|
||||
|
||||
void drawMandelbrot() {
|
||||
void drawMandelbrot(double maxReal = 1.0, double minReal = -2.5,
|
||||
double maxImag = 1.25, double minImag = -1.25) {
|
||||
using namespace Constants;
|
||||
|
||||
double xNorm{};
|
||||
@@ -17,37 +18,85 @@ void drawMandelbrot() {
|
||||
double cReal{};
|
||||
double cImag{};
|
||||
|
||||
for (int x{}; x <= Constants::windowWidth; ++x) {
|
||||
for (int y{}; y <= Constants::windowHeight; ++y) {
|
||||
for (int x{}; x <= windowWidth; ++x) {
|
||||
for (int y{}; y <= 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);
|
||||
cReal = minReal + xNorm * (maxReal - minReal);
|
||||
cImag = minImag + yNorm * (maxImag - minImag);
|
||||
|
||||
int iterationsMandelbrot{calculateMandelbrot(cReal, cImag)};
|
||||
|
||||
float t = static_cast<float>(iterationsMandelbrot) / maxIterations;
|
||||
Color color = LerpColor(BLUE, RED, t);
|
||||
DrawPixel(x, y, color);
|
||||
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() {
|
||||
double maxReal{1.0};
|
||||
double minReal{-2.5};
|
||||
double maxImag{1.25};
|
||||
double minImag{-1.25};
|
||||
InitWindow(Constants::windowWidth, Constants::windowHeight,
|
||||
"Mandelbrot Plot");
|
||||
SetTargetFPS(60);
|
||||
|
||||
RenderTexture2D target =
|
||||
LoadRenderTexture(Constants::windowWidth, Constants::windowHeight);
|
||||
bool needsRedraw = true;
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
if (IsKeyPressed(KEY_UP)) {
|
||||
maxImag += 0.1;
|
||||
minImag += 0.1;
|
||||
needsRedraw = true;
|
||||
std::cout << "Runter!" << '\n';
|
||||
}
|
||||
if (IsKeyPressed(KEY_DOWN)) {
|
||||
maxImag -= 0.1;
|
||||
minImag -= 0.1;
|
||||
needsRedraw = true;
|
||||
std::cout << "Hoch!" << '\n';
|
||||
}
|
||||
if (IsKeyPressed(KEY_LEFT)) {
|
||||
maxReal += 0.1;
|
||||
minReal += 0.1;
|
||||
needsRedraw = true;
|
||||
std::cout << "Links!" << '\n';
|
||||
}
|
||||
if (IsKeyPressed(KEY_RIGHT)) {
|
||||
maxReal -= 0.1;
|
||||
minReal -= 0.1;
|
||||
needsRedraw = true;
|
||||
std::cout << "Rechts!" << '\n';
|
||||
}
|
||||
|
||||
if (needsRedraw) {
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(RAYWHITE);
|
||||
drawMandelbrot(maxReal, minReal, maxImag, minImag);
|
||||
EndTextureMode();
|
||||
needsRedraw = false;
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
drawMandelbrot();
|
||||
DrawTextureRec(
|
||||
target.texture,
|
||||
{0, 0, (float)target.texture.width, -(float)target.texture.height},
|
||||
{0, 0}, WHITE);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadRenderTexture(target);
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user