diff --git a/headers/Mandelbrot.h b/headers/Mandelbrot.h index 31832d2..49612db 100644 --- a/headers/Mandelbrot.h +++ b/headers/Mandelbrot.h @@ -15,17 +15,20 @@ public: void zoomRelative(int, QVector2D); void resizeRelative(QVector2D); bool initShader(); + void initView(QSize); public slots: void toggleAnimation(); void toggleNormalize(); private: + const QVector2D startCenter {-0.66, 0}; + const float startMaxSize = 3; + int maxIterations = 0; float hueAdd = 0; - QVector2D origin {-2, -1}; - QVector2D size {2, 2}; + QVector2D origin; + QVector2D size; float zoomModifier = 1.05; bool normalize = true; - bool animating = true; GLuint vao; diff --git a/src/Mandelbrot.cpp b/src/Mandelbrot.cpp index b212a98..4b0ac15 100644 --- a/src/Mandelbrot.cpp +++ b/src/Mandelbrot.cpp @@ -70,6 +70,19 @@ void Mandelbrot::toggleNormalize() { normalize = !normalize; } +void Mandelbrot::initView(QSize startSize) { + int viewW = startSize.width(); + int viewH = startSize.height(); + float ratio = float(viewW) / float(viewH); + + if (ratio > 1){ + size = {startMaxSize, startMaxSize / ratio}; + } else { + size = {startMaxSize * ratio, startMaxSize}; + } + origin = startCenter - size / 2; +} + diff --git a/src/OutputWidget.cpp b/src/OutputWidget.cpp index 136a894..671dd7f 100644 --- a/src/OutputWidget.cpp +++ b/src/OutputWidget.cpp @@ -82,6 +82,7 @@ void OutputWidget::resizeGL(int w, int h) { QSize newSize = QSize(w, h); if (oldSize == QSize(0, 0)){ oldSize = newSize; + getMandelbrot().initView(newSize); return; } QSize diff = oldSize - newSize;