/* Nadia Susanto
Section B
nsusanto@andrew.cmu.edu
Project-03-Dynamic Drawing */
var angle = 0;
function setup() {
createCanvas(640, 480);
}
function draw() {
background("black");
//background color changes dependent on mouseX
if (mouseX > width/2) {
background(0, 0, 88);
}
noStroke();
//sun
fill(255, 216, 0);
ellipse(320, 240, 150, 150);
//mercury (in solar system is fastest to orbit sun)
fill(223, 126, 83);
push();
translate(320, 240);
rotate(radians(angle*2.5));
ellipse(50, 50, 50, 50);
pop();
//venus (in solar system is 2nd fastest to orbit sun)
//rotates counter-clockwise
fill(222, 184, 135);
push();
translate(320, 240);
rotate(radians(-angle*1.5));
ellipse(75, 100, 75, 75);
pop();
//earth (in solar system is 3rd fastest to orbit sun)
fill(57, 118, 40); //green circle
push();
translate(320, 240);
rotate(radians(angle));
ellipse(150, 100, 100, 100);
pop();
//mars (in solar system is 4th fastest to orbit sun)
fill(165, 42, 42);
push();
translate(320, 240);
rotate(radians(angle*0.5));
ellipse(200, 100, 85, 85);
pop();
angle = angle + 1
//new planet size dependent on mouseX and mouseY
// supposed to resemble neptune, uranus, or pluto (very slow to orbit)
if (mouseX > 395 || mouseY > 315) {
fill(30, 144, 255);
push();
translate(320, 240);
rotate(radians(angle/4));
circle(width-mouseX, height-mouseY, height - mouseY, 150);
}
//comet can move in regards to mouse movement
if (mouseX < 250 & mouseY < 300) {
fill(255, 100, 0);
triangle(mouseX, mouseY, mouseX, mouseY*2, mouseX*4, mouseY*4);
fill(119,136,153);
ellipse(mouseX*4, mouseY*4, mouseX, mouseY);
}
//blackhole spins when pressed
if (mouseIsPressed) {
fill("black");
push();
translate(320, 240);
rotate(-angle);
ellipseMode(CENTER);
ellipse(150, 100, 640, 480);
pop();
angle = angle + 5
}
}
I was inspired by the solar system, so I tried having multiple planets shown with its orbit around the sun and made each speed correspond to how fast or slow they actually orbit the sun in real life. There is a comet shown with certain mouse directions and I tried to make it move with the mouse. If clicked on, I also incorporated a spinning black hole to “terrorize” the universe. Overall, the process was tough as I was not used to the push pop rules and rotation and translation, but I am happy with the finished product.