|
|
|
@ -7,14 +7,29 @@ RenderArea::RenderArea(QWidget *parent) :
|
|
|
|
|
mShapeColour{251,250,250},
|
|
|
|
|
mShape{Astroid}
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
OnShapeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointF RenderArea::ComputeAstroid(float t){
|
|
|
|
|
QPointF RenderArea::ComputeAstroid(double t){
|
|
|
|
|
double cos_t{cos(t)},sin_t{sin(t)},x{2*cos_t*cos_t*cos_t},y{2*sin_t*sin_t*sin_t};
|
|
|
|
|
return QPointF{x,y};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointF RenderArea::ComputeCycloid(double t)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointF RenderArea::ComputeHuygens(double t)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointF RenderArea::ComputeHypo(double t)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize RenderArea::minimumSizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return QSize(100,100);
|
|
|
|
@ -30,40 +45,64 @@ void RenderArea::paintEvent(QPaintEvent* event)
|
|
|
|
|
QPainter painter{this};
|
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing,true);
|
|
|
|
|
|
|
|
|
|
painter.setBrush(mBackgroundColour);
|
|
|
|
|
painter.setPen(mShapeColour);
|
|
|
|
|
|
|
|
|
|
painter.drawRect(this->rect());
|
|
|
|
|
|
|
|
|
|
QPoint center{this->rect().center()};
|
|
|
|
|
double step{ mIntervalLenght / mStepCount };
|
|
|
|
|
|
|
|
|
|
for(float t = 0; t < mIntervalLenght; t += step){
|
|
|
|
|
QPointF point = Compute(t);
|
|
|
|
|
|
|
|
|
|
QPoint pixel;
|
|
|
|
|
pixel.setX(point.x() * mScale + center.x());
|
|
|
|
|
pixel.setY(point.y() * mScale + center.y());
|
|
|
|
|
|
|
|
|
|
painter.drawPoint(pixel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderArea::OnShapeChanged()
|
|
|
|
|
{
|
|
|
|
|
switch (mShape) {
|
|
|
|
|
case Astroid:
|
|
|
|
|
mBackgroundColour = Qt::red;
|
|
|
|
|
mScale=50;
|
|
|
|
|
mIntervalLenght=2*M_PI;
|
|
|
|
|
mStepCount=256;
|
|
|
|
|
break;
|
|
|
|
|
case Cycloid:
|
|
|
|
|
mBackgroundColour = Qt::green;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case HuygensCycloid:
|
|
|
|
|
mBackgroundColour = Qt::blue;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case HypoCycloid:
|
|
|
|
|
mBackgroundColour = Qt::yellow;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
painter.setBrush(mBackgroundColour);
|
|
|
|
|
painter.setPen(mShapeColour);
|
|
|
|
|
|
|
|
|
|
painter.drawRect(this->rect());
|
|
|
|
|
|
|
|
|
|
QPoint center{this->rect().center()};
|
|
|
|
|
int stepCount{1024};
|
|
|
|
|
double scale{40},intervalLenght{2 * M_PI},step{intervalLenght / stepCount};
|
|
|
|
|
for(float t = 0; t < intervalLenght; t += step){
|
|
|
|
|
QPointF point = ComputeAstroid(t);
|
|
|
|
|
|
|
|
|
|
QPoint pixel;
|
|
|
|
|
pixel.setX(point.x() * scale + center.x());
|
|
|
|
|
pixel.setY(point.y() * scale + center.y());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter.drawPoint(pixel);
|
|
|
|
|
QPointF RenderArea::Compute(double t)
|
|
|
|
|
{
|
|
|
|
|
switch (mShape) {
|
|
|
|
|
case Astroid:
|
|
|
|
|
return ComputeAstroid(t);
|
|
|
|
|
break;
|
|
|
|
|
case Cycloid:
|
|
|
|
|
return ComputeCycloid(t);
|
|
|
|
|
break;
|
|
|
|
|
case HuygensCycloid:
|
|
|
|
|
return ComputeHuygens(t);
|
|
|
|
|
break;
|
|
|
|
|
case HypoCycloid:
|
|
|
|
|
return ComputeHypo(t);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QPointF{0,0};
|
|
|
|
|
}
|
|
|
|
|