/*
 * Function: skyColoring
 * Usage: skyColoring(colors,gw);
 * --------------------------
 * Iterates over the graphics window and adds squares of the appropriate color from the sdAlgo grid.
 * Randomly adds stars if night is set to true.
 */
void skyColoring(Grid<int> & colors, GWindow gw){
    double xStep = (double)width/colors.numCols();
    double yStep = (double)height/colors.numRows();
    int starInfreq = 14;
    for(int j=0; j<colors.numRows(); j++){
        for(int i=0; i<colors.numCols(); i++){
            int color = colors[i][j]*RED+(dusk?DUSK_BASE:DAY_BASE);
            if(night){
                color = colors[i][j]*.5;
            }
            GRect *rect = new GRect(xStep*j, yStep*i, xStep, yStep);
            rect->setFilled(true);
            rect->setColor(color);
            gw.add(rect);
            if(night){
                if(rand()%starInfreq==1){
                    GRect *star = new GRect(xStep*j, yStep*i, xStep*STAR_WIDTH, yStep*STAR_WIDTH);
                    star->setFilled(true);
                    star->setColor(WHITE);
                    gw.add(star);
                }
            }
        }
        starInfreq++;
    }
}
Exemple #2
0
//GWindow elements
void update(Grid<int> & board, GWindow & gw, bool loading, double & loadX) {
    //printBoard(board);                                    //NOTE: *****UNCHECK THIS TO SEE THE TEXT BASED VERSION *******
    gw.clear();
    GRect *background = new GRect(gw.getWidth(), gw.getHeight());
    background -> setFillColor("#0000CC");
    background -> setFilled(true);
    gw.add(background, 0, 0);
     
    if(loading) {
        GRect *loading = new GRect(LOAD_WIDTH, LOAD_HEIGHT);
        loading -> setFillColor("#FFCC66");
        loading -> setFilled(true);
        loading -> setColor("#FFCC66");
        gw.add(loading, loadX, 0);
        loadX += 20;
        if(loadX > gw.getWidth()) {
            loadX = -LOAD_WIDTH;
        }
    }
    double spacer = gw.getWidth()/29;
    double x = 0;
    for(int i = 0; i < 7; i++) {
        double y = 0;
        x += spacer;
        for(int j = 0; j < 6; j++) {
            y += spacer;
            string c = "lightGray";
            if(board[j][i] == 1) {
                if(loading) {
                    c = "#990000";
                } else {
                    c = "#C80000";
                }
            } else if (board[j][i] == 2) {
                if(loading) {
                    c = "#000033";
                } else {
                    c = "#660066";
                }
            } else if (board[j][i] == 3) {
                if(loading) {
                    c = "#996633";
                /*} else {
                    c = "#660066";*/
                }
            }
            gw.add(circle(c, spacer), x + i*spacer*3, y + j*spacer*3);
        }
    }
}
/*
 * Function: drawTrunk
 * Usage: drawTrunk(gw, branchStart);;
 * --------------------------
 * Draws a curvy looking trunk structure on the GWindow.
 */
void drawTrunk(GWindow gw, GPoint start){
    GPoint finish = GPoint(start.getX(), height);
    GPolygon * trunk = trunkPolygon(start, finish, BRANCH_THICKNESS);
    trunk->setFilled(true);
    trunk->setColor(4270639);
    gw.add(trunk);
}
/*
 * Function: drawBackGroundMountain
 * Usage:  if(bg->isSelected()) drawBackGroundMountain(gw);
 * --------------------------
 * Adds a mountain to the to the GWindow, and sets it's color depending on the time of day.
 */
void drawBackGroundMountain(GWindow gw){
    GPolygon *mountain = mountainPolygon();
    mountain->setFilled(true);
    mountain->setColor(MOUNTAIN_DAY_COLOR);
    if(!day) mountain->setColor(MOUNTAIN_LATE_COLOR);
    gw.add(mountain);
}
pair<double, double> drawCoordinateSystem(GWindow &graphicsWindow, int scale) {
    pair<double, double> result;
    result.first = graphicsWindow.getWidth() / 2;
    result.second = graphicsWindow.getHeight() / 2;
    graphicsWindow.drawLine(result.first, 0, result.first, result.second * 2);
    graphicsWindow.drawLine(0, result.second, result.first * 2, result.second);
    for (int x = -result.first / scale + 1; x <= result.first / scale - 1; x++)
        graphicsWindow.drawLine(result.first + x * scale, result.second - 5,
                                result.first + x * scale, result.second + 5);
    for (int y = -result.second / scale + 1; y <= result.second / scale - 1; y++)
        graphicsWindow.drawLine(result.first - 5, result.second + y * scale,
                                result.first + 5, result.second + y * scale);
    GLabel* xMark = new GLabel("x", result.first * 2 - 20, result.second + 15);
    graphicsWindow.add(xMark);
    GLabel* yMark = new GLabel("y", result.first + 10, 20);
    graphicsWindow.add(yMark);
    return result;
}
/*
 * Function: drawTriangle
 * Usage: drawTriangle(triangle, gw);
 * --------------------------
 * Given an array of GPoints, this function draws a triangle.
 */
void drawTriangle(GPoint triangle[], GWindow gw){
    GPolygon *tri = new GPolygon();
    for(int i=0; i<3; i++){
        tri->addVertex(triangle[i].getX(), triangle[i].getY());
    }
    tri->setFilled(true);
    tri->setFillColor(TERRAIN_BASE_COLOR+rand()%100);
    gw.add(tri);
}
Exemple #7
0
void drawBranch(GWindow &gw, Branch &branch){
    GLine* br_line=new GLine(branch.start.x,branch.start.y,branch.end.x, branch.end.y);
    br_line->setColor(baseColor);
    if(branch.width==0){
        cout << "w=0"<< endl;
        branch.width=1;
    }
    br_line->setLineWidth(branch.width);
    gw.add(br_line);
}
Exemple #8
0
/* Depending on how you approach your problem decomposition, you
 * may want to rewrite some of these lines, move them inside loops,
 * or move them inside helper functions, etc.
 *
 * TODO: rewrite this comment.
 */
int main() {
    GWindow gw;
    gw.setTitle("Fauxtoshop");
    gw.setVisible(true);

    cout << "Welcome to Fauxtoshop!" << endl;


    cout << "Enter name of image file to open (or blank to quiet): ";

    string img_name;
    getline(cin, img_name);

    cout << "Opening image file, may take a minute..." << endl;

    GBufferedImage img;
    while (!openImageFromFilename(img, img_name))
    {
        cout << "Can't open the file, please enter again: ";
        getline(cin, img_name);
    }

    gw.setSize(img.getWidth(), img.getHeight());
    gw.add(&img,0,0);

    string menu = "Which image filter would you like to apply?\n"
                  "         1 - Scatter\n"
                  "         2 - Edge detection\n"
                  "         3 - \"Green screen\" with another image\n"
                  "         4 - Compare image with another image";
    cout << menu << endl;

    string choice_str = "Your choice: ";
    int choice = getInteger(choice_str, choice_str);

    switch(choice)
    {
        case 1:
            scatter(img);
            break;
        case 2:
            edge_detection(img);
            break;
        case 3:
            green_screen(img);
            break;
    }


    int row, col;
    getMouseClickLocation(row, col);
    return 0;
}
/*
 * Function: drawLightning
 * Usage: if(lightning->isSelected()) drawLightning(gw, GPoint(width*randomReal(.2, .8), 0), GPoint(width*randomReal(.2, .8), height));
 * --------------------------
 * Adds a lightning shaped polygon to the screen that branches off probabilistically.
 */
void drawLightning(GWindow gw, GPoint start, GPoint end){
    GPolygon *lightning = lightningPolygon(start, end);
    lightning->setFilled(true);
    lightning->setColor(LIGHTNING_OUTER_COLOR);
    lightning->setFillColor(LIGHTNING_INNER_COLOR);
    gw.add(lightning);
    if(randomChance(.7)){
        Vector<GPoint> points = lightning->getVertices();
        start = points[points.size()/4];
        drawLightning(gw, start,GPoint(start.getX(), height));
    }
}
Exemple #10
0
/*
 * Function: drawBranch
 * Usage: drawBranch(gw, branchStart, GPoint(width*(xMult-.15), height*(yMult-.15)), BRANCH_THICKNESS);
 * --------------------------
 * Draws branches that continue and branch of probabilistically.
 */
void drawBranch(GWindow gw, GPoint start, GPoint finish, double width){
    GPolygon *branch = branchPolygon(start, finish, width);
    branch->setFilled(true);
    branch->setColor(4270639);
    gw.add(branch);
    Vector<GPoint> points = branch->getVertices();
    start = points[points.size()/4];
    double endX = randomReal(start.getX()*(1-TREE_DEFORMATION), start.getX()*(1+TREE_DEFORMATION));
    double endY = randomReal(1+TREE_DEFORMATION, 1+2*TREE_DEFORMATION)*(finish.getY()-start.getY())+start.getY();
    if((endY-finish.getY())<-3){
        drawBranch(gw, start,GPoint(endX, endY),width/2);
    }
}
Exemple #11
0
/*
 * Function: drawSun
 * Usage: if(sun->isSelected()) drawSun(gw,MAX_SUN_RADIUS,(dusk?DUSK_SUN_COLOR:DAY_SUN_COLOR));
 * --------------------------
 * Uses a recursive function to draw the sun/moon as series of concentric circles.
 * Totally unnecessary to do this recursively, but it's the recursive contest. #YOLO
 */
int drawSun(GWindow gw, int radius, int color){
    if(radius<=0){
        return 0;
    }
    GOval *oval;
    if(dusk){
        oval = new GOval(width/4-radius,height*.45-radius,radius*2,radius*2);
    }
    else{
        radius/=2;
        oval = new GOval(2.0*width/3.0-radius,height/3.0-radius,radius*2,radius*2);
        radius*=2;
    }
    oval->setColor(color);
    oval->setFilled(true);
    oval->setColor(color);
    gw.add(oval);
    radius--;
    color -=2;
    return drawSun(gw, radius, color);
}
Exemple #12
0
/* Depending on how you approach your problem decomposition, you
 * may want to rewrite some of these lines, move them inside loops,
 * or move them inside helper functions, etc.
 *
 * TODO: rewrite this comment.
 */
int main() {
    GWindow gw;
    gw.setTitle("Fauxtoshop");
    gw.setVisible(true);
    GBufferedImage img;
    while (true) {
        ifstream infile;
        cout << "Welcome to Fauxtoshop!" << endl;
        string prompt = "Enter the name of image file to open (or blank to quit):";
        string filename= openFile(infile, prompt, img);
        if (filename == "") break;
        gw.setSize(img.getWidth(), img.getHeight());
        gw.add(&img,0,0);
        int choice = chooseFilter();
        dealWithImage(img, choice);
        saveImage(img);
    }


    /*int row, col;
    getMouseClickLocation(row, col);*/
    return 0;
}
void gbufferedImageTest() {
    GWindow gw;
    gw.setSize(900, 700);
    gw.setTitle("Test");

    GButton* button1 = new GButton("Click Me 1");
    gw.add(button1, 250, 80);
    //GButton* button2 = new GButton("Click Me 2");
    //gw.addToRegion(button2, "NORTH");

    GLabel* label = new GLabel("test!");
    gw.add(label, 10, 60);
    
    std::cout << "About to construct GBufferedImage." << std::endl;
    GBufferedImage* img = new GBufferedImage(10, 80, 200, 250);
    std::cout << "Done constructing GBufferedImage." << std::endl;
    gw.add(img, 50, 50);
    // gw.addToRegion(img, "SOUTH");
    gw.setVisible(true);
    
//    GBufferedImage* img2 = new GBufferedImage(20, 20);
//    img2->fill(GBufferedImage::createRgbPixel(255, 0, 255));
//    Grid<int> grid = img2->toGrid();
//    cout << "grid of pixels before: " << grid << endl;
//    for (int y = 4; y <= 18; y++) {
//        for (int x = 2; x <= 9; x++) {
//            grid[y][x] = GBufferedImage::createRgbPixel(0, 255, 0);
//        }
//    }
//    cout << "grid of pixels after: " << grid << endl;
//    img2->fromGrid(grid);
//    gw.add(img2, 350, 20);
    
    GBufferedImage* img3 = new GBufferedImage();
    img3->load("rainbow.png");
    cout << "adding the image!" << endl;
    gw.add(img3, 10, 20);
    // pause(2000);
    
    cout << "start toGrid" << endl;
    Grid<int> grid3 = img3->toGrid();
    cout << "end toGrid, start rgb shit" << endl;
    for (int y = 0; y < grid3.height(); y++) {
        for (int x = 0; x < grid3.width(); x++) {
            int red, green, blue;
            GBufferedImage::getRedGreenBlue(grid3[y][x], red, green, blue);
            grid3[y][x] = GBufferedImage::createRgbPixel(green, red, blue);
        }
    }
    cout << "end rgb shit, start fromGrid" << endl;
    img3->fromGrid(grid3);
    cout << "end fromGrid" << endl;
    
    pause(2000);
    return;

    // fill
    img->fill(0xff00ff);  // purple

    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 2; y < img->getHeight() - 2; y++) {
        for (int x = 5; x <= img->getWidth() - 5; x++) {
            img->setRGB(x, y, 0xffcc33);
        }
    }
    std::cout << "Done setting RGB on GBufferedImage." << std::endl;
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(100, 50);
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(200, 80);
    border(img);
    pause(500);
    
    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 10; y < img->getHeight() - 10; y++) {
        for (int x = 10; x <= img->getWidth() - 10; x++) {
            img->setRGB(x, y, 0xff33cc);
        }
    }
    border(img);
    
    std::cout << "About to remove other shit." << std::endl;
    pause(200);
    gw.remove(label);
    gw.remove(button1);
    //gw.removeFromRegion(button2, "NORTH");
    pause(200);
    
    std::cout << "About to remove GBufferedImage." << std::endl;
    pause(200);
    gw.remove(img);
    // gw.removeFromRegion(img, "SOUTH");
    pause(200);
    std::cout << "Test complete." << std::endl;
    std::cout << std::endl;
}