vtavarez-project-05-wallpaper

sketch-246.js

//Victor Tavarez
//Section D
//vtavarez@andrew.cmu.edu
//Assignment-05-B

function setup() {
    createCanvas(500, 500);

}


function draw() {
    background(100,100,255);
    for (var x=0; x<=width; x+=50){
        for(var y=0; y<=height; y+=50) {
            drawT(x,y);
            drawV(x,y);
            
        }
    }
    for(var x=0; x<=width; x+=50){
        for(var y=-25; y<=height+25; y+=50){
            drawDot(x,y);
        }
    }
    for(var x=0; x<=width; x+=50){
        for(var y=0;y<=height;y+=50){
            drawSquares(x,y);
        }
    }
}

function drawSquares(x,y){
    noStroke();
    fill(255,100,100);
    if (x/50%2==1){ //50 since x is in terms of pixels
        rect(x-10,y-10,5,5);
        rect(x+5,y-10,5,5);
    } else{
        rect(x-10,y+5,5,5);
        rect(x+5,y+5,5,5);
    }
}

function drawDot(x,y){ //creates a dot before T/V figure
    noStroke();    
    fill(0,100,240);
    ellipse(x,y,5,5);
}

function drawV(xV1,yV1){ //draws V shape at every T
    var xV2 = xV1-5;
    var xV3 = xV1+5;  
    var yV2 = yV1-15;//arrow up
    var yV3 = yV1+15;//arrow down
    
    stroke(220,100,245);
    strokeWeight(2)
    if (xV1/50%2==1) {//depending on the column the figure flips
        line(xV1,yV1,xV3,yV3);
        line(xV1,yV1,xV2,yV3);
    } else{
        line(xV1,yV1,xV2,yV2);
        line(xV1,yV1,xV3,yV2);
    }
}

function drawT(xT1,yT1){
    var xT2 = xT1-15;
    var yT2 = yT1;
    var xT3 = xT1+15;
    var yT3 = yT1;
    var xT4 = xT1;
    var yT4 = yT1-15;
    //upsidedownT
    var xT5 = xT1;
    var yT5 = yT1+15;

    stroke(220,100,245);
    strokeWeight(2);
    // if statment will alternate the direction of the T's
    if ((xT1/50)%2==1){
        line(xT2,yT2,xT3,yT3);
        line(xT1,yT1,xT4,yT4);
    } else{
        line(xT2,yT2,xT3,yT3);  
        line(xT1,yT1,xT5,yT5);

    }
}

Leave a Reply