Robert Oh Project-05-Wallpaper

version2

//Robert Oh
//Section C
//rhoh@andrew.cmu.edu
//Project-05-Wallpaper

//assigning variables
var x = 0;
var y = 0;

function tile(x, y) {
    //creating the top border of each tile
    strokeWeight(5);
    stroke(6, 54, 132);
    fill(0);
    rect(x*250, y*100 + 2, 250, 10);

    stroke(0);
    //this x + y % 2 alternates every tile 
    if ((x + y) % 2 == 0){
        //creates gap
        rect(x*250, y*100, 70, 20);
        
        //making pacman
        fill(235, 255, 58);
        arc(x*250 + 45, y*100 + 53, 50, 50, PI/4, -(PI/4));

        //making the smaller dots
        fill(255);
        ellipse(x*250 + 85, y*100 + 53, 12, 12);
        ellipse(x*250 + 125, y*100 + 53, 12, 12);
        ellipse(x*250 + 165, y*100 + 53, 12, 12);

        //making the larger "power-up" dot
        ellipse(x*250 + 205, y*100 + 53, 20, 20);
    }
    else {
        //creating the gap
        rect(x*250 + 175, y*100, 70, 20);

        //pacman
        fill(235, 255, 58);
        arc(x*250 + 205, y*100 + 53, 50, 50, PI+PI/4, PI-(PI/4));

        //creating the smaller dots
        fill(255);
        ellipse(x*250 + 85, y*100 + 53, 12, 12);
        ellipse(x*250 + 125, y*100 + 53, 12, 12);
        ellipse(x*250 + 165, y*100 + 53, 12, 12);

        //creating the power-up dot
        ellipse(x*250 + 45, y*100 + 53, 20, 20);
    }
}

function setup() {
    createCanvas(500, 500);
    background(0);
    //nested for loop to fill up my wallpaper with my pacman tiles
    for (y = 0; y < 5; y ++){
        for (x = 0; x < 2; x++){
            tile(x, y);
        }
    }

    //creating borders and middle line
    fill(0);
    strokeWeight(5);
    stroke(6, 54, 132);
    rect(245, 0, 10, 500);
    rect(0, 487, 500, 10);
    rect(0, 0, 10, 500);
    rect(488, 0, 10, 500);

    //creating a gap on the bottom
    stroke(0);
    rect(245, 417, 20, 65);

    noLoop();
}

function draw() {
    //nothing here because noLoop is called
}

When I started this project, I was brainstorming for ideas to create my tiles with. I am a huge video gamer, and so I thought a cute little Pacman “maze” would be cute to code. I designed the background and details to match those of the actual original game (with the blue walls, black background, white pellets and bigger “power-up pellets”. All in all, I love how it ended up looking!

Leave a Reply