sleeping earth, suns, moons, and stars!
sketch
// Sowang Kundeling skundeli Section C Project 05
var angle = 0;
var x = 480/2;
var y = 480;
var z = 60; // size
function setup() {
createCanvas(480, 480);
}
function draw() {
background('black');
push();
frameRate(1);
translate(240, 480);
rotate(radians(7) * second());
galaxy();
pop();
noStroke();
fill('black')
var eyeLX = x + 60
var eyeRX = x - 60
ellipse(eyeLX, y-60, z+10, z); // left eye
ellipse(eyeRX, y-60, z+10, z); // right eye
fill(9, 130, 13);
ellipse(eyeLX, y-75, z+15, z); // cut out left eye
ellipse(eyeRX, y-75, z+15, z) // cut out right eye
push();
frameRate(1);
translate(x-120, y-350);
rotate(radians(5) * second());
star(0+minute(), 0+minute(), 10, 30, 5); // left star
pop();
push();
frameRate(1);
translate(x+120, y-380);
rotate(-radians(5) * second());
star(0+minute(), 0+minute(), 5, 20, 5); // right star
pop();
}
function galaxy() {
// earth
translate(-240, -480);
fill(9, 130, 13); // green
noStroke();
circle(x, y, z*5);
// yellow
noStroke();
fill(245, 206, 51); // yellow
circle(x, y-200, z);
fill(242, 221, 136); // inner yellow
circle(x, y-200, z/2)
// orange
fill(245, 145, 51); // orange
circle(x+200, y, z);
fill(242, 188, 138); // inner orange
circle(x+200, y, z/2);
// dark blue
fill(74, 51, 245); // dark blue
circle(x, y+200, z);
fill(167, 156, 247); // inner dark blue
circle(x, y+200, z/2);
// light blue
fill(150, 198, 250); // light blue
circle(x-200, y, z);
fill(211, 227, 245); // inner light blue
circle(x-200, y, z/2)
}
function star(x, y, radius1, radius2, npoints) { // reference star https://editor.p5js.org/p5/sketches/Form:_Star
fill(241, 242, 153)
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}