more shapes

This commit is contained in:
thepra 2017-09-09 22:28:27 +02:00
parent c152ff4dec
commit 3b0554cb87
5 changed files with 195 additions and 8 deletions

View File

@ -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);

View File

@ -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;

View File

@ -365,6 +365,54 @@ border-color: rgb(255, 255, 255);</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCircle">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Circle</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnEllipse">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Ellipse</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnFancy">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Fancy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnStarfish">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Starfish</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
@ -388,6 +436,12 @@ border-color: rgb(255, 255, 255);</string>
</item>
<item>
<widget class="QDoubleSpinBox" name="scaleInput">
<property name="maximumSize">
<size>
<width>61</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);</string>
@ -396,7 +450,7 @@ background-color: rgb(36, 35, 35);</string>
<number>1</number>
</property>
<property name="maximum">
<double>100.000000000000000</double>
<double>150.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
@ -428,6 +482,24 @@ background-color: rgb(36, 35, 35);</string>
</item>
<item>
<widget class="QDoubleSpinBox" name="intervalInput">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>61</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>61</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);</string>
@ -465,6 +537,12 @@ background-color: rgb(36, 35, 35);</string>
</item>
<item>
<widget class="QSpinBox" name="stepInput">
<property name="maximumSize">
<size>
<width>61</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);</string>

View File

@ -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;
}

View File

@ -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;