code handles curves dinamically
This commit is contained in:
parent
4f847aa671
commit
66b3828254
@ -6,13 +6,28 @@ RenderArea::RenderArea(QWidget *parent) :
|
|||||||
mBackgroundColour{36,35,35},
|
mBackgroundColour{36,35,35},
|
||||||
mShapeColour{251,250,250},
|
mShapeColour{251,250,250},
|
||||||
mShape{Astroid}
|
mShape{Astroid}
|
||||||
|
{
|
||||||
|
OnShapeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
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::ComputeAstroid(float t){
|
QPointF RenderArea::ComputeHuygens(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::ComputeHypo(double t)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize RenderArea::minimumSizeHint() const
|
QSize RenderArea::minimumSizeHint() const
|
||||||
@ -30,40 +45,64 @@ void RenderArea::paintEvent(QPaintEvent* event)
|
|||||||
QPainter painter{this};
|
QPainter painter{this};
|
||||||
painter.setRenderHint(QPainter::Antialiasing,true);
|
painter.setRenderHint(QPainter::Antialiasing,true);
|
||||||
|
|
||||||
switch (mShape) {
|
|
||||||
case Astroid:
|
|
||||||
mBackgroundColour = Qt::red;
|
|
||||||
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.setBrush(mBackgroundColour);
|
||||||
painter.setPen(mShapeColour);
|
painter.setPen(mShapeColour);
|
||||||
|
|
||||||
painter.drawRect(this->rect());
|
painter.drawRect(this->rect());
|
||||||
|
|
||||||
QPoint center{this->rect().center()};
|
QPoint center{this->rect().center()};
|
||||||
int stepCount{1024};
|
double step{ mIntervalLenght / mStepCount };
|
||||||
double scale{40},intervalLenght{2 * M_PI},step{intervalLenght / stepCount};
|
|
||||||
for(float t = 0; t < intervalLenght; t += step){
|
for(float t = 0; t < mIntervalLenght; t += step){
|
||||||
QPointF point = ComputeAstroid(t);
|
QPointF point = Compute(t);
|
||||||
|
|
||||||
QPoint pixel;
|
QPoint pixel;
|
||||||
pixel.setX(point.x() * scale + center.x());
|
pixel.setX(point.x() * mScale + center.x());
|
||||||
pixel.setY(point.y() * scale + center.y());
|
pixel.setY(point.y() * mScale + center.y());
|
||||||
|
|
||||||
painter.drawPoint(pixel);
|
painter.drawPoint(pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderArea::OnShapeChanged()
|
||||||
|
{
|
||||||
|
switch (mShape) {
|
||||||
|
case Astroid:
|
||||||
|
mScale=50;
|
||||||
|
mIntervalLenght=2*M_PI;
|
||||||
|
mStepCount=256;
|
||||||
|
break;
|
||||||
|
case Cycloid:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case HuygensCycloid:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case HypoCycloid:
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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};
|
||||||
|
}
|
||||||
|
14
renderarea.h
14
renderarea.h
@ -21,7 +21,7 @@ class RenderArea : public QWidget
|
|||||||
|
|
||||||
void setBackgroundColor(QColor color) { mBackgroundColour = color; }
|
void setBackgroundColor(QColor color) { mBackgroundColour = color; }
|
||||||
QColor backgroundColor() const { return mBackgroundColour; }
|
QColor backgroundColor() const { return mBackgroundColour; }
|
||||||
void setShape(ShapesType shape) { mShape = shape; }
|
void setShape(ShapesType shape) { mShape = shape; OnShapeChanged(); }
|
||||||
ShapesType shape() const { return mShape; }
|
ShapesType shape() const { return mShape; }
|
||||||
|
|
||||||
|
|
||||||
@ -33,9 +33,15 @@ class RenderArea : public QWidget
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointF ComputeAstroid(float t);
|
void OnShapeChanged();
|
||||||
QColor mBackgroundColour;
|
QPointF ComputeAstroid(double t);
|
||||||
QColor mShapeColour;
|
QPointF ComputeCycloid(double t);
|
||||||
|
QPointF ComputeHuygens(double t);
|
||||||
|
QPointF ComputeHypo(double t);
|
||||||
|
QPointF Compute(double t);
|
||||||
|
QColor mBackgroundColour,mShapeColour;
|
||||||
ShapesType mShape;
|
ShapesType mShape;
|
||||||
|
double mScale,mIntervalLenght;
|
||||||
|
int mStepCount;
|
||||||
};
|
};
|
||||||
#endif // RENDERAREA_H
|
#endif // RENDERAREA_H
|
||||||
|
Loading…
Reference in New Issue
Block a user