summaryrefslogtreecommitdiffstats
path: root/examples/corelib/threads/mandelbrot/renderthread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/corelib/threads/mandelbrot/renderthread.cpp')
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/examples/corelib/threads/mandelbrot/renderthread.cpp b/examples/corelib/threads/mandelbrot/renderthread.cpp
index eee44c7242..22ce81c32d 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.cpp
+++ b/examples/corelib/threads/mandelbrot/renderthread.cpp
@@ -57,9 +57,6 @@
RenderThread::RenderThread(QObject *parent)
: QThread(parent)
{
- restart = false;
- abort = false;
-
for (int i = 0; i < ColormapSize; ++i)
colormap[i] = rgbFromWaveLength(380.0 + (i * 400.0 / ColormapSize));
}
@@ -102,10 +99,10 @@ void RenderThread::run()
{
forever {
mutex.lock();
- QSize resultSize = this->resultSize;
- double scaleFactor = this->scaleFactor;
- double centerX = this->centerX;
- double centerY = this->centerY;
+ const QSize resultSize = this->resultSize;
+ const double scaleFactor = this->scaleFactor;
+ const double centerX = this->centerX;
+ const double centerY = this->centerY;
mutex.unlock();
//! [3]
@@ -128,20 +125,20 @@ void RenderThread::run()
if (abort)
return;
- uint *scanLine =
+ auto scanLine =
reinterpret_cast<uint *>(image.scanLine(y + halfHeight));
- double ay = centerY + (y * scaleFactor);
+ const double ay = centerY + (y * scaleFactor);
for (int x = -halfWidth; x < halfWidth; ++x) {
- double ax = centerX + (x * scaleFactor);
+ const double ax = centerX + (x * scaleFactor);
double a1 = ax;
double b1 = ay;
int numIterations = 0;
do {
++numIterations;
- double a2 = (a1 * a1) - (b1 * b1) + ax;
- double b2 = (2 * a1 * b1) + ay;
+ const double a2 = (a1 * a1) - (b1 * b1) + ax;
+ const double b2 = (2 * a1 * b1) + ay;
if ((a2 * a2) + (b2 * b2) > Limit)
break;
@@ -187,9 +184,9 @@ void RenderThread::run()
//! [10]
uint RenderThread::rgbFromWaveLength(double wave)
{
- double r = 0.0;
- double g = 0.0;
- double b = 0.0;
+ double r = 0;
+ double g = 0;
+ double b = 0;
if (wave >= 380.0 && wave <= 440.0) {
r = -1.0 * (wave - 440.0) / (440.0 - 380.0);