Project 4, odh

odhP4

//Owen D Haft
//Section D
//odh@andrew.cmu.edu
//Project 4

var W = 1;  //Value of strokeweight
var B = 150;//Value of B in RGB

function setup() {
    createCanvas(400, 300);
}
 
function draw() {
    background(50, 50, B);
    strokeWeight(W);

    //Sets up the series of lines and how they move with the mouse's location
    for(var i = 0; i < 20; i ++){
        line(mouseX, i*20, 400-i*10, height);
        line(mouseX, i*20, i*10, height);
        line(400, i*20, 100+i*10, mouseY);
        line(0, i*20, 100+i*10, mouseY);
    };

    //Determines the color of the background and 
    // the strokeweight of th lines based on the mouse's location
    if (mouseX > width/2) {
        W = 2;
        B = 255;
    } else {
        W = 1;
        B = 150;
    };
    if (mouseY > height/2) {
        W = 3;
        B = 0;
    } else {
        W = 1;
        B = 150;
    }; 
}

I used some simple loops to have the arrangement of the series of lines be determined by the mouse’s location. Then I practiced more with “if” statements and added some conditionals.

Leave a Reply