From 3b0554cb876b78a2d4a536e27ea72c54ab8819a4 Mon Sep 17 00:00:00 2001 From: thepra Date: Sat, 9 Sep 2017 22:28:27 +0200 Subject: [PATCH] more shapes --- mainwindow.cpp | 28 ++++++++++++++++++ mainwindow.h | 8 +++++ mainwindow.ui | 80 +++++++++++++++++++++++++++++++++++++++++++++++++- renderarea.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++---- renderarea.h | 12 ++++++-- 5 files changed, 195 insertions(+), 8 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 32c0bc1..6773daa 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -64,6 +64,34 @@ void MainWindow::on_btnLine_clicked() UpdateUi(); } +void MainWindow::on_btnCircle_clicked() +{ + this->ui->renderArea->setShape(RenderArea::Circle); + this->ui->renderArea->repaint(); + UpdateUi(); +} + +void MainWindow::on_btnEllipse_clicked() +{ + this->ui->renderArea->setShape(RenderArea::Ellipse); + this->ui->renderArea->repaint(); + UpdateUi(); +} + +void MainWindow::on_btnFancy_clicked() +{ + this->ui->renderArea->setShape(RenderArea::Fancy); + this->ui->renderArea->repaint(); + UpdateUi(); +} + +void MainWindow::on_btnStarfish_clicked() +{ + this->ui->renderArea->setShape(RenderArea::Starfish); + this->ui->renderArea->repaint(); + UpdateUi(); +} + void MainWindow::on_intervalInput_valueChanged(double interval) { this->ui->renderArea->setInternalLenght(interval); diff --git a/mainwindow.h b/mainwindow.h index 4336790..40ec709 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -39,6 +39,14 @@ class MainWindow : public QMainWindow void on_btnLineColor_clicked(); + void on_btnCircle_clicked(); + + void on_btnEllipse_clicked(); + + void on_btnFancy_clicked(); + + void on_btnStarfish_clicked(); + private: void UpdateUi(); constexpr static QWidget* root = 0; diff --git a/mainwindow.ui b/mainwindow.ui index 0b342c6..3a3f096 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -365,6 +365,54 @@ border-color: rgb(255, 255, 255); + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Circle + + + + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Ellipse + + + + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Fancy + + + + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Starfish + + + @@ -388,6 +436,12 @@ border-color: rgb(255, 255, 255); + + + 61 + 16777215 + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); @@ -396,7 +450,7 @@ background-color: rgb(36, 35, 35); 1 - 100.000000000000000 + 150.000000000000000 0.100000000000000 @@ -428,6 +482,24 @@ background-color: rgb(36, 35, 35); + + + 0 + 0 + + + + + 61 + 0 + + + + + 61 + 16777215 + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); @@ -465,6 +537,12 @@ background-color: rgb(36, 35, 35); + + + 61 + 16777215 + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); diff --git a/renderarea.cpp b/renderarea.cpp index 45b636f..836c237 100644 --- a/renderarea.cpp +++ b/renderarea.cpp @@ -40,6 +40,11 @@ void RenderArea::paintEvent(QPaintEvent* event) prevPixel=pixel; } + QPointF point = Compute(mIntervalLenght); + QPoint pixel{}; + pixel.setX(point.x() * mScale + center.x()); + pixel.setY(point.y() * mScale + center.y()); + painter.drawLine(pixel, prevPixel); } RenderArea::RenderArea(QWidget *parent) : @@ -87,17 +92,45 @@ QPointF RenderArea::ComputeLine(double t) return QPointF{1-t,1-t}; } +QPointF RenderArea::ComputeCircle(double t) +{ + return QPointF{cos(t),sin(t)}; +} + +QPointF RenderArea::ComputeEllipse(double t) +{ + double a{2},b{1.1}; + return QPointF{a*cos(t),b*sin(t)}; +} + +QPointF RenderArea::ComputeFancy(double t) +{ + return QPointF{ + 11*cos(t) - 6*cos((11.0/6)*t), + 11*sin(t) - 6*sin((11.0/6)*t) + }; +} + +QPointF RenderArea::ComputeStarfish(double t) +{ + double R{5},r{3},d{5}; + return QPointF{ + (R-r)*cos(t) + d*cos(t*((R-r)/r)), + (R-r)*sin(t) - d*sin(t*((R-r)/r)) + }; +} + void RenderArea::OnShapeChanged() { switch (mShape) { case Astroid: - mScale=50; + mScale=90; mIntervalLenght=2*M_PI; mStepCount=512; break; case Cycloid: mScale=10; - mIntervalLenght=6*M_PI; + mIntervalLenght=4*M_PI; mStepCount=128; break; case HuygensCycloid: @@ -106,15 +139,35 @@ void RenderArea::OnShapeChanged() mStepCount=512; break; case HypoCycloid: - mScale=50; + mScale=40; mIntervalLenght=2*M_PI; mStepCount=256; break; case Line: - mScale=50; - mIntervalLenght=1; + mScale=100; + mIntervalLenght=2; mStepCount=128; break; + case Circle: + mScale=100; + mIntervalLenght=2*M_PI; + mStepCount=128; + break; + case Ellipse: + mScale=75; + mIntervalLenght=2*M_PI; + mStepCount=256; + break; + case Fancy: + mScale=10; + mIntervalLenght=12*M_PI; + mStepCount=512; + break; + case Starfish: + mScale=25; + mIntervalLenght=6*M_PI; + mStepCount=256; + break; default: break; } @@ -138,6 +191,18 @@ QPointF RenderArea::Compute(double t) case Line: return ComputeLine(t); break; + case Circle: + return ComputeCircle(t); + break; + case Ellipse: + return ComputeEllipse(t); + break; + case Fancy: + return ComputeFancy(t); + break; + case Starfish: + return ComputeStarfish(t); + break; default: break; } diff --git a/renderarea.h b/renderarea.h index b5a9a45..d420d6d 100644 --- a/renderarea.h +++ b/renderarea.h @@ -17,7 +17,11 @@ class RenderArea : public QWidget Cycloid, HuygensCycloid, HypoCycloid, - Line + Line, + Circle, + Ellipse, + Fancy, + Starfish }; void setBackgroundColor(QColor color) { mBackgroundColour = color; } @@ -47,12 +51,16 @@ class RenderArea : public QWidget private: void OnShapeChanged(); + QPointF Compute(double t); QPointF ComputeAstroid(double t); QPointF ComputeCycloid(double t); QPointF ComputeHuygens(double t); QPointF ComputeHypo(double t); QPointF ComputeLine(double t); - QPointF Compute(double t); + QPointF ComputeCircle(double t); + QPointF ComputeEllipse(double t); + QPointF ComputeFancy(double t); + QPointF ComputeStarfish(double t); QColor mBackgroundColour,mShapeColour; ShapesType mShape; double mScale,mIntervalLenght;