diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2008-10-07 03:14:22 -0400 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2008-10-07 03:14:22 -0400 |
commit | 5992a30de22ae688e87371094049cf627ca7da5d (patch) | |
tree | 8fde70da016b6babeab4f9c4d8b7d10ab16c912d | |
parent | Initial commit (diff) | |
download | trianglefractalchaos-5992a30de22ae688e87371094049cf627ca7da5d.tar.xz trianglefractalchaos-5992a30de22ae688e87371094049cf627ca7da5d.zip |
Improved proportion and initial point placement algorithm.
-rw-r--r-- | TriangleFractalChaos.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/TriangleFractalChaos.cpp b/TriangleFractalChaos.cpp index daa3bd0..72b5303 100644 --- a/TriangleFractalChaos.cpp +++ b/TriangleFractalChaos.cpp @@ -7,6 +7,7 @@ #include <QTimer> #include <QPixmap> #include <cstdlib> +#include <QDebug> TriangleFractalChaos::TriangleFractalChaos(QWidget *parent) : QWidget(parent) @@ -48,19 +49,31 @@ void TriangleFractalChaos::toggleDraw() magnification->setEnabled(false); generate->setText("&Stop"); setFixedSize(size()); - int width = this->width(); - int height = (int)((double)width * 1.73205081 / 2.0); - width /= (int)magnification->value(); - height /= (int)magnification->value(); - dots = new QImage(width, height, QImage::Format_RGB32); + int width, height; + if(this->width() < this->height()) { + width = this->width(); + height = qRound((double)width * 1.73205081 / 2.0); + } else { + height = this->height(); + width = qRound((double)height * 1.73205081 / 2.0); + } + int deltaWidthHalf = qRound(((double)(this->width() - width)) / 2.0) / magnification->value(); + int deltaHeightHalf = qRound(((double)(this->height() - height)) / 2.0) / magnification->value(); + width /= magnification->value(); + height /= magnification->value(); + dots = new QImage(size() / magnification->value(), QImage::Format_RGB32); dots->fill(backgroundColor); - startingPoints[0] = QPoint(width / 2 - 1, 0); - startingPoints[1] = QPoint(0, height - 1); - startingPoints[2] = QPoint(width - 1, height - 1); + startingPoints[0] = QPoint(qRound((double)width / 2.0) - 1 + deltaWidthHalf, deltaHeightHalf); + startingPoints[1] = QPoint(deltaWidthHalf, height - 1 + deltaHeightHalf); + startingPoints[2] = QPoint(width - 1 + deltaWidthHalf, height - 1 + deltaHeightHalf); dots->setPixel(startingPoints[0], 0xff00ff00); dots->setPixel(startingPoints[1], 0xff00ff00); dots->setPixel(startingPoints[2], 0xff00ff00); - lastPoint = QPoint(rand() % width + 1, rand() % height + 1); + int randomX = rand() % (width + 1); + int yStart = height - qRound((double)height / ((double)width / 2.0) * (double)randomX); + if(yStart < 0) yStart *= -1; + int randomY = (rand() % (height - yStart + 1)) + yStart; + lastPoint = QPoint(randomX + deltaWidthHalf, randomY + deltaHeightHalf); dots->setPixel(lastPoint, 0xffff0000); update(); drawTimer->start(delay->value()); |