Project-03

sketch

//Cora Hickoff
//Section D 
//chickoff@andrew.cmu.edu
//Project-03

function setup() {
    createCanvas(640, 480);
    rectMode(CENTER);
    frameRate(10);
}

function draw() {

    //mouseX controls the degrees
    var deg = mouseX;
    var rad = radians(deg);

    background(144,180,180);
    //make background change color
    //when mouse midway point of canvas width
    if (mouseX > (width / 2)) {
        background (232,180,180);
    }

    //small gold circle
    fill(255, 214, 169);
    noStroke();
    //restrict mouseX to 0-135
    var m = max(min(mouseX, 40), 135);
    var size = m * 120.0 / 400.0;
    ellipse(10 + m * 190.0 / 400.0, 200.0, size, size);

    //white circle
    fill(255);
    noStroke();
    //restrict mouseX to 0-400
    var m = max(min(mouseX, 400), 35);
    var size = m * 120.0 / 300.0;
    ellipse(10 + m * 190.0 / 400.0, 200.0, size, size);

    //big gold circle
    fill(255, 214, 169);
    noStroke();
    //restrict mouseX to 0-335
    //mouseX, 920 causes mouseX 
    //to control bid golden circle
    //once white circle overlaps
    var m = max(min(mouseX, 920), 335);
    var size = m * 120.0 / 400.0;
    ellipse(10 + m * 190.0 / 400.0, 200.0, size, size);

    //peach square
    fill(240,140,130);
    //as mouseX moves across
    //canvas, its degrees determine
    //the square's rotation
    rotate(rad);
    rect(300 + m * 190.0 / 400.0, 200.0, size, size);

}

In this project, I wanted to make a shape rotate based on the mouse’s x coordinates. By adding the other ellipses, I realized that the end result made them all look like planets in a solar system and the rectangle looked as though it were orbiting them.

Leave a Reply