more shapes
This commit is contained in:
		@@ -64,6 +64,34 @@ void MainWindow::on_btnLine_clicked()
 | 
				
			|||||||
	UpdateUi();
 | 
						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)
 | 
					void MainWindow::on_intervalInput_valueChanged(double interval)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	this->ui->renderArea->setInternalLenght(interval);
 | 
						this->ui->renderArea->setInternalLenght(interval);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,14 @@ class MainWindow : public QMainWindow
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		void on_btnLineColor_clicked();
 | 
							void on_btnLineColor_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void on_btnCircle_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void on_btnEllipse_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void on_btnFancy_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void on_btnStarfish_clicked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		void UpdateUi();
 | 
							void UpdateUi();
 | 
				
			||||||
		constexpr static QWidget* root = 0;
 | 
							constexpr static QWidget* root = 0;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -365,6 +365,54 @@ border-color: rgb(255, 255, 255);</string>
 | 
				
			|||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </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>
 | 
					      <item>
 | 
				
			||||||
       <layout class="QHBoxLayout" name="horizontalLayout_3">
 | 
					       <layout class="QHBoxLayout" name="horizontalLayout_3">
 | 
				
			||||||
        <item>
 | 
					        <item>
 | 
				
			||||||
@@ -388,6 +436,12 @@ border-color: rgb(255, 255, 255);</string>
 | 
				
			|||||||
        </item>
 | 
					        </item>
 | 
				
			||||||
        <item>
 | 
					        <item>
 | 
				
			||||||
         <widget class="QDoubleSpinBox" name="scaleInput">
 | 
					         <widget class="QDoubleSpinBox" name="scaleInput">
 | 
				
			||||||
 | 
					          <property name="maximumSize">
 | 
				
			||||||
 | 
					           <size>
 | 
				
			||||||
 | 
					            <width>61</width>
 | 
				
			||||||
 | 
					            <height>16777215</height>
 | 
				
			||||||
 | 
					           </size>
 | 
				
			||||||
 | 
					          </property>
 | 
				
			||||||
          <property name="styleSheet">
 | 
					          <property name="styleSheet">
 | 
				
			||||||
           <string notr="true">color: rgb(255, 255, 255);
 | 
					           <string notr="true">color: rgb(255, 255, 255);
 | 
				
			||||||
background-color: rgb(36, 35, 35);</string>
 | 
					background-color: rgb(36, 35, 35);</string>
 | 
				
			||||||
@@ -396,7 +450,7 @@ background-color: rgb(36, 35, 35);</string>
 | 
				
			|||||||
           <number>1</number>
 | 
					           <number>1</number>
 | 
				
			||||||
          </property>
 | 
					          </property>
 | 
				
			||||||
          <property name="maximum">
 | 
					          <property name="maximum">
 | 
				
			||||||
           <double>100.000000000000000</double>
 | 
					           <double>150.000000000000000</double>
 | 
				
			||||||
          </property>
 | 
					          </property>
 | 
				
			||||||
          <property name="singleStep">
 | 
					          <property name="singleStep">
 | 
				
			||||||
           <double>0.100000000000000</double>
 | 
					           <double>0.100000000000000</double>
 | 
				
			||||||
@@ -428,6 +482,24 @@ background-color: rgb(36, 35, 35);</string>
 | 
				
			|||||||
        </item>
 | 
					        </item>
 | 
				
			||||||
        <item>
 | 
					        <item>
 | 
				
			||||||
         <widget class="QDoubleSpinBox" name="intervalInput">
 | 
					         <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">
 | 
					          <property name="styleSheet">
 | 
				
			||||||
           <string notr="true">color: rgb(255, 255, 255);
 | 
					           <string notr="true">color: rgb(255, 255, 255);
 | 
				
			||||||
background-color: rgb(36, 35, 35);</string>
 | 
					background-color: rgb(36, 35, 35);</string>
 | 
				
			||||||
@@ -465,6 +537,12 @@ background-color: rgb(36, 35, 35);</string>
 | 
				
			|||||||
        </item>
 | 
					        </item>
 | 
				
			||||||
        <item>
 | 
					        <item>
 | 
				
			||||||
         <widget class="QSpinBox" name="stepInput">
 | 
					         <widget class="QSpinBox" name="stepInput">
 | 
				
			||||||
 | 
					          <property name="maximumSize">
 | 
				
			||||||
 | 
					           <size>
 | 
				
			||||||
 | 
					            <width>61</width>
 | 
				
			||||||
 | 
					            <height>16777215</height>
 | 
				
			||||||
 | 
					           </size>
 | 
				
			||||||
 | 
					          </property>
 | 
				
			||||||
          <property name="styleSheet">
 | 
					          <property name="styleSheet">
 | 
				
			||||||
           <string notr="true">color: rgb(255, 255, 255);
 | 
					           <string notr="true">color: rgb(255, 255, 255);
 | 
				
			||||||
background-color: rgb(36, 35, 35);</string>
 | 
					background-color: rgb(36, 35, 35);</string>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,6 +40,11 @@ void RenderArea::paintEvent(QPaintEvent* event)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		prevPixel=pixel;
 | 
							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) :
 | 
					RenderArea::RenderArea(QWidget *parent) :
 | 
				
			||||||
@@ -87,17 +92,45 @@ QPointF RenderArea::ComputeLine(double t)
 | 
				
			|||||||
	return QPointF{1-t,1-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()
 | 
					void RenderArea::OnShapeChanged()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	switch (mShape) {
 | 
						switch (mShape) {
 | 
				
			||||||
		case Astroid:
 | 
							case Astroid:
 | 
				
			||||||
			mScale=50;
 | 
								mScale=90;
 | 
				
			||||||
			mIntervalLenght=2*M_PI;
 | 
								mIntervalLenght=2*M_PI;
 | 
				
			||||||
			mStepCount=512;
 | 
								mStepCount=512;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
		case Cycloid:
 | 
							case Cycloid:
 | 
				
			||||||
			mScale=10;
 | 
								mScale=10;
 | 
				
			||||||
			mIntervalLenght=6*M_PI;
 | 
								mIntervalLenght=4*M_PI;
 | 
				
			||||||
			mStepCount=128;
 | 
								mStepCount=128;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
		case HuygensCycloid:
 | 
							case HuygensCycloid:
 | 
				
			||||||
@@ -106,15 +139,35 @@ void RenderArea::OnShapeChanged()
 | 
				
			|||||||
			mStepCount=512;
 | 
								mStepCount=512;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
		case HypoCycloid:
 | 
							case HypoCycloid:
 | 
				
			||||||
			mScale=50;
 | 
								mScale=40;
 | 
				
			||||||
			mIntervalLenght=2*M_PI;
 | 
								mIntervalLenght=2*M_PI;
 | 
				
			||||||
			mStepCount=256;
 | 
								mStepCount=256;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
		case Line:
 | 
							case Line:
 | 
				
			||||||
			mScale=50;
 | 
								mScale=100;
 | 
				
			||||||
			mIntervalLenght=1;
 | 
								mIntervalLenght=2;
 | 
				
			||||||
			mStepCount=128;
 | 
								mStepCount=128;
 | 
				
			||||||
		break;
 | 
							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:
 | 
							default:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -138,6 +191,18 @@ QPointF RenderArea::Compute(double t)
 | 
				
			|||||||
		case Line:
 | 
							case Line:
 | 
				
			||||||
			return ComputeLine(t);
 | 
								return ComputeLine(t);
 | 
				
			||||||
		break;
 | 
							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:
 | 
							default:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								renderarea.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								renderarea.h
									
									
									
									
									
								
							@@ -17,7 +17,11 @@ class RenderArea : public QWidget
 | 
				
			|||||||
			Cycloid,
 | 
								Cycloid,
 | 
				
			||||||
			HuygensCycloid,
 | 
								HuygensCycloid,
 | 
				
			||||||
			HypoCycloid,
 | 
								HypoCycloid,
 | 
				
			||||||
			Line
 | 
								Line,
 | 
				
			||||||
 | 
								Circle,
 | 
				
			||||||
 | 
								Ellipse,
 | 
				
			||||||
 | 
								Fancy,
 | 
				
			||||||
 | 
								Starfish
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void setBackgroundColor(QColor color) { mBackgroundColour = color; }
 | 
							void setBackgroundColor(QColor color) { mBackgroundColour = color; }
 | 
				
			||||||
@@ -47,12 +51,16 @@ class RenderArea : public QWidget
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		void OnShapeChanged();
 | 
							void OnShapeChanged();
 | 
				
			||||||
 | 
							QPointF Compute(double t);
 | 
				
			||||||
		QPointF ComputeAstroid(double t);
 | 
							QPointF ComputeAstroid(double t);
 | 
				
			||||||
		QPointF ComputeCycloid(double t);
 | 
							QPointF ComputeCycloid(double t);
 | 
				
			||||||
		QPointF ComputeHuygens(double t);
 | 
							QPointF ComputeHuygens(double t);
 | 
				
			||||||
		QPointF ComputeHypo(double t);
 | 
							QPointF ComputeHypo(double t);
 | 
				
			||||||
		QPointF ComputeLine(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;
 | 
							QColor mBackgroundColour,mShapeColour;
 | 
				
			||||||
		ShapesType mShape;
 | 
							ShapesType mShape;
 | 
				
			||||||
		double mScale,mIntervalLenght;
 | 
							double mScale,mIntervalLenght;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user