change iteration count to max iteration count naming in software

master
Benjamin Kraft 3 years ago
parent b1894ad4d4
commit 7340f95ed6
  1. 8
      Fragment.glsl
  2. 6
      headers/Mandelbrot.h
  3. 28
      src/MainWindow.cpp
  4. 6
      src/Mandelbrot.cpp

@ -1,7 +1,7 @@
#version 330 core #version 330 core
out vec4 pixColor; out vec4 pixColor;
uniform int iterationCount; uniform int maxIterationsCount;
uniform float hueAdd; uniform float hueAdd;
in vec2 complexPos; in vec2 complexPos;
@ -47,16 +47,16 @@ float mandelbrot(in vec2 c){
vec2 z = vec2(0, 0); vec2 z = vec2(0, 0);
float steps = 0; float steps = 0;
float escapeSquared = pow(1 << 8, 2); float escapeSquared = pow(1 << 8, 2);
while (steps < iterationCount && pow(z.x, 2) + pow(z.y, 2) < escapeSquared){ while (steps < maxIterationsCount && pow(z.x, 2) + pow(z.y, 2) < escapeSquared){
z = m(z); z = m(z);
++steps; ++steps;
} }
if (steps == iterationCount) if (steps == maxIterationsCount)
return 0.; return 0.;
float log_zn = log(z.x * z.x + z.y * z.y) / 2; float log_zn = log(z.x * z.x + z.y * z.y) / 2;
float nu = log(log_zn / log(2)) / log(2); float nu = log(log_zn / log(2)) / log(2);
steps += 1 - nu; steps += 1 - nu;
float t = steps / iterationCount; float t = steps / maxIterationsCount;
return sqrt(t); return sqrt(t);
} }

@ -11,14 +11,14 @@ public:
void draw(); void draw();
void updateAnimation(); void updateAnimation();
void toggleAnimation(); void toggleAnimation();
void setIterations(int); void setMaxIterations(int);
void translateRelative(QVector2D); void translateRelative(QVector2D);
void zoomRelative(int, QVector2D); void zoomRelative(int, QVector2D);
void resizeRelative(QVector2D); void resizeRelative(QVector2D);
bool initShader(); bool initShader();
private: private:
int iterations = 0; int maxIterations = 0;
float hueAdd = 0.0; float hueAdd = 0;
QVector2D origin {-2, -1}; QVector2D origin {-2, -1};
QVector2D size {2, 2}; QVector2D size {2, 2};
float zoomModifier = 1.05; float zoomModifier = 1.05;

@ -12,22 +12,22 @@ MainWindow::MainWindow(): outputWidget(OutputWidget(this)) {
void MainWindow::buildUI() { void MainWindow::buildUI() {
resize(700, 700); resize(700, 700);
auto iterationsCaption = new QLabel("Iteration count: "); auto maxIterationsCaption = new QLabel("Max iteration count: ");
auto iterationsLabel = new QLabel; auto maxIterationsLabel = new QLabel;
iterationsLabel->setFixedWidth(50); maxIterationsLabel->setFixedWidth(50);
iterationsLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight); maxIterationsLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
auto iterationsSlider = new QSlider(Qt::Horizontal); auto maxIterationsSlider = new QSlider(Qt::Horizontal);
iterationsSlider->setRange(5, 1000); maxIterationsSlider->setRange(5, 1000);
connect( connect(
iterationsSlider, maxIterationsSlider,
&QSlider::valueChanged, &QSlider::valueChanged,
this, this,
[iterationsLabel, this](int value) -> void { [maxIterationsLabel, this](int value) -> void {
this->outputWidget.getMandelbrot().setIterations(value); this->outputWidget.getMandelbrot().setMaxIterations(value);
this->outputWidget.update(); this->outputWidget.update();
iterationsLabel->setNum(value); maxIterationsLabel->setNum(value);
}); });
iterationsSlider->setValue(100); maxIterationsSlider->setValue(100);
auto saveInfo = new QLabel; auto saveInfo = new QLabel;
auto saveButton = new QPushButton("Save high resolution image"); auto saveButton = new QPushButton("Save high resolution image");
@ -56,9 +56,9 @@ void MainWindow::buildUI() {
}); });
auto controls = new QGridLayout; auto controls = new QGridLayout;
controls->addWidget(iterationsCaption, 1, 1); controls->addWidget(maxIterationsCaption, 1, 1);
controls->addWidget(iterationsLabel, 1, 2); controls->addWidget(maxIterationsLabel, 1, 2);
controls->addWidget(iterationsSlider, 1, 3); controls->addWidget(maxIterationsSlider, 1, 3);
controls->addWidget(saveInfo, 2, 1, 1, 2); controls->addWidget(saveInfo, 2, 1, 1, 2);
controls->addWidget(saveButton, 2, 3, 1, 1); controls->addWidget(saveButton, 2, 3, 1, 1);
controls->addWidget(animButton, 3, 1, 1, 3); controls->addWidget(animButton, 3, 1, 1, 3);

@ -39,7 +39,7 @@ bool Mandelbrot::initShader() {
void Mandelbrot::setShaderValues() { void Mandelbrot::setShaderValues() {
shader.setUniformValue("origin", origin); shader.setUniformValue("origin", origin);
shader.setUniformValue("size", size); shader.setUniformValue("size", size);
shader.setUniformValue("iterationCount", iterations); shader.setUniformValue("maxIterationsCount", maxIterations);
shader.setUniformValue("hueAdd", hueAdd); shader.setUniformValue("hueAdd", hueAdd);
} }
@ -52,8 +52,8 @@ void Mandelbrot::zoomRelative(int direction, QVector2D posRelative) {
origin = newOrigin; origin = newOrigin;
} }
void Mandelbrot::setIterations(int value) { void Mandelbrot::setMaxIterations(int value) {
iterations = value; maxIterations = value;
} }
void Mandelbrot::translateRelative(QVector2D relative) { void Mandelbrot::translateRelative(QVector2D relative) {

Loading…
Cancel
Save