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