Exemple #1
0
int main (int argc, char** argv)
{
    QApplication app(argc, argv);

    QGraphicsView view;
    QGraphicsScene *scene = new QGraphicsScene(&view);
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);

    Line *left, *right, *right2;

    int of = pos_x;

    for(int i = 0; i < c; i++)
    {
        Line* ball = new Line(QPoint(of, -2));
        scene->addItem(ball);
        of += size;
        if(i==0)
            left = ball;
        else if(i == c - 1)
            right = ball;
        else if(i == c - 2)
            right2 = ball;
    }

    QTimeLine *LeftTimerTo      = newAnim(left,0,45,QEasingCurve::OutQuart);
    QTimeLine *LeftTimerReturn    = newAnim(left,45,0,QEasingCurve::InQuart);
    QTimeLine *RightTimerTo     = newAnim(right,0,-45,QEasingCurve::OutQuart);
    QTimeLine *RightTimerBack   = newAnim(right,-45,0,QEasingCurve::InQuart);
    QTimeLine *RightTimerTo2     = newAnim(right2,0,-45,QEasingCurve::OutQuart);
    QTimeLine *RightTimerBack2   = newAnim(right2,-45,0,QEasingCurve::InQuart);



    scene->setSceneRect(0, 0, 940, 460);

    view.setCacheMode(QGraphicsView::CacheBackground);
    view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    view.setScene(scene);
    view.resize(960, 480);
    view.show();

    QObject::connect(LeftTimerTo,   SIGNAL(finished()), LeftTimerReturn,  SLOT(start()));
    QObject::connect(LeftTimerReturn, SIGNAL(finished()), RightTimerTo,   SLOT(start()));
    QObject::connect(LeftTimerReturn, SIGNAL(finished()), RightTimerTo2,   SLOT(start()));
    QObject::connect(RightTimerTo,  SIGNAL(finished()), RightTimerBack, SLOT(start()));
    QObject::connect(RightTimerTo2,  SIGNAL(finished()), RightTimerBack2, SLOT(start()));
    QObject::connect(RightTimerBack,SIGNAL(finished()), LeftTimerTo,    SLOT(start()));

    LeftTimerReturn->start();

    return app.exec();
}
Exemple #2
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QGraphicsScene scene;
    QGraphicsView *view = new QGraphicsView(&scene);
    Window *w = new Window;
    scene.addItem(w);
    view->resize(400, 300);
    view->show();
    return app.exec();
}
Exemple #3
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QGraphicsScene scene;
    QGraphicsView *view = new QGraphicsView(&scene);
    Window *w = new Window;
    scene.addItem(w);

#if defined(Q_OS_SYMBIAN)
    view->showMaximized();
#else
    view->resize(400, 300);
    view->show();
#endif

    return app.exec();
}
Exemple #4
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGraphicsScene *scene = new QGraphicsScene;
    scene->setSceneRect(QRectF(-200,-200,400,400));

    Butterfly *butterfly = new Butterfly;
    butterfly->setPos(-100,0);

    scene->addItem(butterfly);

    QGraphicsView *view = new QGraphicsView;
    view->setScene(scene);
    view->resize(450,450);
    view->show();

    return a.exec();
}
Exemple #5
0
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // open file
    string filename = "input12800.txt";
    ifstream input;
    input.open(filename);

    // the vector of points
    vector<Point> points;

    // read points from file
    int N;
    int x;
    int y;

    input >> N;

    for (int i = 0; i < N; ++i) {
        input >> x >> y;
        points.push_back(Point(x, y));
    }
    input.close();

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
    view->setScene(scene);
    // draw points to screen all at once
    render_points(scene, points);
    view->scale(1, -1); //screen y-axis is inverted
    view->resize(view->sizeHint());
    view->setWindowTitle("Brute Force Pattern Recognition");
    view->show();

    // sort points by natural order
    // makes finding endpoints of line segments easy
    sort(points.begin(), points.end());
    auto begin = chrono::high_resolution_clock::now();

    for(int i = 0; i < N-3;++i){
        Point p = points.at(i);
        // Skapar en ny lista som innehåller alla punkter som ligger efter p
        vector<Point> slopeList;
        for (int j = i+1; j < N;++j){
            slopeList.push_back(points.at(j));
        }
        // Sorterar den nya listan beorende på lutningen till p
        sort(slopeList.begin(),slopeList.end(),comparator(p));
        // De två senaste punkterna vi har kollat på
        Point sameSlope [2] = {
            slopeList.at(0),
            slopeList.at(1)
        };
        for(int j = 2;j < N-i-1;++j){
            // Kollar om båda punkterna i sameSlope och den nuvarande punkten har samma lutning mot p
            if(p.slopeTo(sameSlope[0]) == p.slopeTo(sameSlope[1]) && p.slopeTo(sameSlope[0]) == p.slopeTo(slopeList[j])){
                // Isåfall kollar vi vilken av de som har högst x-värde och ritar en linje från p till den
                Point largestX = sameSlope[0] > sameSlope[1] ? sameSlope[0] : sameSlope[1];
                largestX = largestX > slopeList.at(j) ? largestX : slopeList.at(j);
                render_line(scene,p,largestX);
                a.processEvents();
            }
            // Lägger in varannan punkt i slopeList[0] och varannan i slopeList[1]
            sameSlope[j%2] = slopeList[j];
        }
    }
    auto end = chrono::high_resolution_clock::now();
    cout << "Computing line segments took "
         << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count()
         << " milliseconds." << endl;

    return a.exec(); // start Qt event loop
}
Exemple #6
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QGraphicsScene *scene = new QGraphicsScene();

    Widget *a = new Widget(Qt::blue, Qt::white, "a");
    a->setPreferredSize(100, 100);
    Widget *b = new Widget(Qt::green, Qt::black, "b");
    b->setPreferredSize(100, 100);
    Widget *c = new Widget(Qt::red, Qt::black, "c");
    c->setPreferredSize(100, 100);

    QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
/*
    //! [adding a corner anchor in two steps]
    layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
    layout->addAnchor(a, Qt::AnchorLeft, layout, Qt::AnchorLeft);
    //! [adding a corner anchor in two steps]
*/
    //! [adding a corner anchor]
    layout->addCornerAnchors(a, Qt::TopLeftCorner, layout, Qt::TopLeftCorner);
    //! [adding a corner anchor]

    //! [adding anchors]
    layout->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight);
    layout->addAnchor(b, Qt::AnchorTop, a, Qt::AnchorBottom);
    //! [adding anchors]

    // Place a third widget below the second.
    layout->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);

/*
    //! [adding anchors to match sizes in two steps]
    layout->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
    layout->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight);
    //! [adding anchors to match sizes in two steps]
*/

    //! [adding anchors to match sizes]
    layout->addAnchors(b, c, Qt::Horizontal);
    //! [adding anchors to match sizes]

    // Anchor the bottom-right corner of the third widget to the bottom-right
    // corner of the layout.
    layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner);

    QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    w->setPos(20, 20);
    w->setMinimumSize(100, 100);
    w->setPreferredSize(320, 240);
    w->setLayout(layout);
    w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
    scene->addItem(w);

    QGraphicsView *view = new QGraphicsView();
    view->setScene(scene);
    view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
    view->resize(360, 320);
    view->show();

    return app.exec();
}
Exemple #7
0
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // open file
    string filename = "input100.txt";
    ifstream input;
    input.open(filename);

    // the vector of points
    vector<Point> points;

    // read points from file
    int N;
    int x;
    int y;

    input >> N;

    for (int i = 0; i < N; ++i) {
        input >> x >> y;
        points.push_back(Point(x, y));
    }
    input.close();

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
    view->setScene(scene);
    // draw points to screen all at once
    render_points(scene, points);
    view->scale(1, -1); //screen y-axis is inverted
    view->resize(view->sizeHint());
    view->setWindowTitle("Brute Force Pattern Recognition");
    view->show();

    // sort points by natural order
    // makes finding endpoints of line segments easy
    sort(points.begin(), points.end());
    auto begin = chrono::high_resolution_clock::now();

    //for each point int points
    for (unsigned int i=0;i<points.size();i++){
        //we create a map with the slope as key and a vector of points as value
        map<double,vector<Point>> point_map;

        //for each point that is "larger" than the point we takes its slopes to the current point i
        for (unsigned int j=i+1;j<points.size();++j){
            //and adds it to the maps in the vector with all other points with the same slope
            point_map[points.at(i).slopeTo(points.at(j))].push_back(points.at(j));
        }
        //after this we iterate through each key in the map
        for (map<double,vector<Point>>::iterator it=point_map.begin(); it!=point_map.end(); ++it){
            //and check if the vector has a size of of three or more
            if (it->second.size()>=3){
                //creates a line
                render_line(scene,points.at(i),*(it->second.end()-1));
                //process the event
                a.processEvents();
            }
        }


    }


    auto end = chrono::high_resolution_clock::now();
    cout << "Computing line segments took "
         << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count()
         << " milliseconds." << endl;

    return a.exec(); // start Qt event loop
}
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // open file
    string filename = "input12800.txt";
    ifstream input;
    input.open(filename);


    // read points from file
    int N;
    int x;
    int y;

    input >> N;

    // the vector of points
    vector<Point> points;
    // a vector of pointers to the points in points
    vector<Point*> pointPointers;

    for (int i = 0; i < N; ++i) {
        input >> x >> y;
        Point* p = new Point(x, y);
        points.push_back(*p);
        pointPointers.push_back(p);
    }
    input.close();

    // setup graphical window
    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
    view->setScene(scene);
    // draw points to screen all at once
    render_points(scene, points);
    view->scale(1, -1); //screen y-axis is inverted
    view->resize(view->sizeHint());
    view->setWindowTitle("Extra Fast Pattern Recognition");
    view->show();
    auto begin = chrono::high_resolution_clock::now();
    //do all of this using each point as starting point
    for (int startingPoint = 0; startingPoint < N; ++startingPoint) {
        vector<PointComparison> comparisons;
        //iterate over all except the starting point. Instead of
        //checking each point if it is a starting point, iterate first
        //over all points until the starting point, and then after.
        for (int i = 0; i < startingPoint; ++i) {
            //for every point that isn't the starting point, create a PointComparison of
            //the starting point pointer and the point pointer at index i.
            comparisons.push_back(PointComparison(pointPointers[startingPoint], pointPointers[i]));
        }
        for (int i = startingPoint + 1; i < N; ++i) {
            //do the same here.
            comparisons.push_back(PointComparison(pointPointers[startingPoint], pointPointers[i]));
        }
        //sort the comparisons by slope
        sort(comparisons.begin(), comparisons.end());

        //start finding collinear lines. Create an index variable.
        int i = 0;
        //since we are checking two points ahead, and checking every point except the starting point,
        //we check from i = 0 to N-1-2 = N-3.
        while (i < N - 3) {
            //get the slopes of this index and the one two indexes away
            double slope1 = comparisons[i].slope;
            double slope2 = comparisons[i + 2].slope;
            //if they are equal, that means we have found four aligned points (including the startingPoint)!
            //Lets see if we can find more...
            //EXTRATASK E8: Because of how the list is sorted, several equal slopes in a row will be sorted
            //lexicographically, which means that the last of these points will be the upmost right point.
            //This also means that the starting point is the downmost left point if and only if it follows
            //the order of the comparison list. That is, only if it is "less" than the first point with equal
            //slope. Since we only want to draw one single line segment between these lines, we include this
            //as a condition to draw the line.
            if (slope1 == slope2 && *comparisons[0].comparePoint < *comparisons[i].thisPoint) {
                int j = i + 3;
                while (slope1 == comparisons[j].slope && j < N - 1) {
                    //we found another aligned point!
                    j++;
                }
                //okay, so the compared point at comparisons[j] was not aligned, so we will
                //just draw a line from the starting point to the one at j-1 (since that was the
                //last aligned point). We use comparisons[0] to get the starting point but
                //we could just use any element in comparisons since they all have the same
                //pointer to the starting point.
                render_line(scene, *comparisons[0].comparePoint, *comparisons[j-1].thisPoint);
                a.processEvents(); // show rendered line
                //continue searching from where the last aligned point was found.
                i = j - 1;
            } else {
                //okay, we didn't find aligned points here, increment and continue.
                i++;
            }
        }
    }
    //And we're done! Pause the timer.
    auto end = chrono::high_resolution_clock::now();
    cout << "Computing line segments took "
         << std::chrono::duration_cast<chrono::milliseconds>(end - begin).count()
         << " milliseconds." << endl;
    return a.exec();
}