#include "mainwindowimpl.h"#include <QGraphicsScene>#include <QPointF>#include <QPainterPath>#include <QPen>//#include <QColor>#include <QBrush>#include <QTime>#include <QDebug>#include <math.h>//MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) : QMainWindow(parent, f){ setupUi(this); connect (cmdGo, SIGNAL(clicked()), this, SLOT(Go())); connect (cmdClear, SIGNAL(clicked()), this, SLOT(clear())); QWidget * w = new QWidget; w->setLayout(basic); setCentralWidget(w); GS = new QGraphicsScene; GV->setScene(GS); GV->scale(130,130); konstr(); QTime timer; timer.start(); qsrand(timer.second()); }//--------------------------------QPointF MainWindowImpl::func(double x){ QPointF point; point.setX(pow(sin(x),2)); point.setY(sin(x-2)); return point; //x(t)=sin^2(t), y(t)=sin(t-2)}//--------------------------------void MainWindowImpl::Go(){ clear(); double x,y; QGraphicsEllipseItem * item; while (spinBox->value()){ spinBox->setValue(spinBox->value()-1); x=rand()%100/100.0; y=rand()%200/100.0-1; /* В ТОЧКЕ Х и У НУЖНО ОПРЕДЕЛИТЬ ЦВЕТ*/ item=GS->addEllipse(x,-y, 0.01,0.01); }}//-------------------------------void MainWindowImpl::konstr(){ path = new QPainterPath; path->moveTo(func(0)); for (double i=0; i<2*M_PI; i+=0.01){ path->lineTo(func(i)); } //QGraphicsPathItem * addPath ( const QPainterPath & path, const QPen & pen = QPen(), const QBrush & brush = QBrush() ) QPen pen(Qt::darkCyan); QBrush brush(Qt::darkCyan); GS->addPath(*path, pen, brush); GS->addRect(0,-1,1,2);}void MainWindowImpl::clear(){ GS->clear(); QPen pen(Qt::darkCyan); QBrush brush(Qt::darkCyan); GS->addPath(*path, pen, brush); GS->addRect(0,-1,1,2);}//
void MainWindowImpl::Go(){ clear(); double x,y; QGraphicsItem * item; int count=spinBox->value(), countTrue=0; while (spinBox->value()){ spinBox->setValue(spinBox->value()-1); x=rand()%100/100.0; y=rand()%200/100.0-1; item=GS->addEllipse(x,-y, 0.01,0.01); if (item->collidesWithPath(*path)) countTrue++; } txtOut->setText(QString::number((countTrue/(double)count)*2));}