dayoungl – Project03

sketch

// Sharon Lee
// Section E
// dayoungl@andrew.cmu.edu
// Project-03
var colour1 = 255;
var colour2 = 235;
var colour3 = 107;
var angle = 0;
var x = 350;
var y = 350;
var dirX = 1;
var dirY = 0.3;
var speed = 5;
var cirSize = 80;
var point1 = 650;
var point2 = 350;
var point3 = 50;
var front = 1;
var count = 0;

function setup() {
    createCanvas(640,480);
    angleMode(DEGREES);
}
function draw() {
    background(0);
    rectMode(CENTER); 
    //moon 1 in front of the planet
    if (front == 1){
        //planet
        fill(colour1,colour2,colour3);
        noStroke();
        ellipse(width/2 +50, height/2, 300,300);
        //moon1
        fill(colour1);
        noStroke();
        ellipse(x, height/2, cirSize, cirSize);
    }
    //moon 1 behind planet
    if (front == 0){
        //moon1
        fill(colour1);
        noStroke();
        ellipse(x, height/2, cirSize, cirSize);
        //planet
        fill(colour1,colour2,colour3);
        noStroke();
        ellipse(width/2 +50, height/2, 300,300);
    }
    //stars that follow mouseX and mouseY
    push();
    angle = angle + 50;
    translate(mouseX,mouseY);
    stroke(139,94,193);
    strokeWeight(10);
    rotate(angle);
    rectMode(CENTER);
    rect(0, 0, 40, 30);
    rotate(angle);
    rect(0, 0, 40, 30);
    rotate(angle);
    rect(0, 0, 40, 30);
    pop();

    //star2
    push();
    angle += 1;
    translate(mouseX -60, mouseY -60);
    stroke(73,50,102);
    strokeWeight(7);
    rotate(angle);
    rect(0,0,10,20);
    rotate(angle);
    rect(0,0,10,20);
    rotate(angle);
    rect(0,0,10,20);
    pop();

    //star3
    fill(73,111,102);
    noStroke();
    ellipse(mouseX, mouseY -100, 10,10);
    //star4
    ellipse(mouseX, mouseY,8,8);
    //star5
    ellipse(mouseX-80, mouseY-55, 15,15);
   
    //location of moon1
    if (x <= point1){  
        x += dirX * speed;
    }
    if (x <= point1 & x >= 350){
        cirSize -= 1;
    }
    if (x <= 350 & x >= point3){
        cirSize += 1;
    }
    if (x >= point1) {
        dirX = -dirX;
        front = 0;
    }
    if (cirSize <= 350 & x <= point3) {
        dirX = -dirX;
        front = 1;
        count += 1;
    }

    // planet changes color every revolution
    if (count % 10 == 1) {
        colour1 = 255;
        colour2 = 235;
        colour3 = 68;
    }
    if (count % 10 == 2) {
        colour1 = 255;
        colour2 = 215;
        colour3 = 68;

    }
    if (count % 10 == 3) {
        colour1 = 255;
        colour2 = 195;
        colour3 = 68;
    } 
    if (count % 10 == 4) {
        colour1 = 255;
        colour2 = 180;
        colour3 = 68;
    }
    if (count % 10 == 5){
        colour1 = 255;
        colour2 = 165;
        colour3 = 68;
    }
    if (count % 10 == 6){
        colour1 = 255;
        colour2 = 150;
        colour3 = 68;
    }
    if (count % 10 == 7){
        colour1 = 255;
        colour2 = 135;
        colour3 = 68;
    }
    if (count % 10 == 8){
        colour1 = 255;
        colour2 = 120;
        colour3 = 68;
    }
    if (count % 10 == 9){
        colour1 = 255;
        colour2 = 105;
        colour3 = 68;
    }
}

Orbital system
I wanted to make an image of moon orbiting the planet along with with other visual decorations that move around as the mouse moves. I had difficulty making the moon go behind the planet every revolution but I eventually figured it out.

Leave a Reply