void test_window_torture() {
    for (int i = 0; i < 10; i++) {
        GWindow *window = new GWindow(200, 200);
        GOval oval(100, 100);
        window->setColor("red");
        window->drawOval(10, 10, 150, 80);
        //pause(100);
        window->close();
        delete window;
    }
}
Exemplo n.º 2
0
//builds two lines from each of two gotten vertex and calls itself recursively until the depth of recursion becomes zero
void drawPythagoreanTree(GWindow &gw, GPoint endPoint1, GPoint endPoint2, double input_length, double theta, int recursion_depth){
        double theta_one = theta - THETA;
        double theta_two = theta + THETA;

        double length = input_length * cos(THETA_RADIAN);

        GPoint branch1_1 = gw.drawPolarLine(endPoint1, length*2, theta_one);
        GPoint branch1_2 = gw.drawPolarLine(endPoint2, length, theta_one);
        gw.setColor("YELLOW");
        gw.drawLine(branch1_1, branch1_2);
        GPoint branch2_1 = gw.drawPolarLine(endPoint1, length, theta_two);
        GPoint branch2_2 = gw.drawPolarLine(endPoint2, length*2, theta_two);
        gw.setColor("GREEN");
        gw.drawLine(branch2_1, branch2_2);

        recursion_depth--;

        if(recursion_depth == 0){
            return;
        }
        drawPythagoreanTree(gw, branch1_1, branch1_2, length, theta_one, recursion_depth);
        drawPythagoreanTree(gw, branch2_1, branch2_2, length, theta_two, recursion_depth);

}
Exemplo n.º 3
0
static void drawTree(GWindow& window, int order, GPoint startPoint, int startAngle, double len) {
    if (order == 0)
    {
        window.setColor(kLeafColor);
        window.drawPolarLine(startPoint, len, startAngle);
    }
    else
    {
        double nextLen = len * kShrinkFactor;

        window.setColor(order < 2 ? kLeafColor : kTrunkColor);
        GPoint trunkEnd = window.drawPolarLine(startPoint, len, startAngle);

        for (int i = 0; i < 7; ++i)
        {
            if (randomReal(0.0, 1.0) < 0.8)
            {
                int angle = startAngle - 45 + i * kBranchAngleSeparation;
            
                drawTree(window, order - 1, trunkEnd, angle, nextLen);
            }  
        }
    }
}