sketch
/*Carley Johnson
cbjohnso@andrew.cmu.edu
Section E
Project 3
*/
var x = 80;
var y = 30;
var w = 12;
var h = 12;
var starR = 252
var starG = 234
var starB = 109
var moonR = 236
var moonG = 236
var moonB = 236
var moonR2 = 109
var moonG2 = 110
var moonB2 = 106
var bckgrndR = 37
var bckgrndG = 21
var bckgrndB = 66
function setup() {
createCanvas(640, 480);
frameRate(10);
}
function draw() {
background(bckgrndR, bckgrndG, bckgrndB)
fill(252, 234, 109)
noStroke()
ellipse(mouseX, mouseY, 10, 10) //constellation
fill(moonR, moonG, moonB)
ellipse(100, 100, 80, 80) //moon
fill(moonR2, moonG2, moonB2)
ellipse(115, 100, 50, 70) //moon dark side
stroke(252, 234, 109)
line(mouseX, mouseY, pmouseX, pmouseY);
print(pmouseX + ' -> ' + mouseX); //constellation maker
noStroke()
fill(starR, starG, starB) //Begin stars for night sky
ellipse(x, y, w, h);
ellipse(x + 80, y + 310, w, h); //star 1
ellipse(30, y + 400, w, h - 2); //star 2
ellipse(x + 10, y + 190, w, h); //star 3
ellipse(x + 200, y +30, w, h); //star 4
ellipse(x + 250, y + 90, w - 2, h - 2); //star 5
ellipse(x + 270, y + 380, w, h); //star 6
ellipse(x + 180, y + 30, w - 2, h -2); //star 7
ellipse(x + 400, y + 75, w - 2, h - 2); //star 8
ellipse(x + 420, y + 300, w, h); //star 9
ellipse(x + 370, y + 130, w - 2, h - 2); //star 10
ellipse(x + 500, y + 30, w, h); //star 11
ellipse(x + 20, y + 285, w, h); //star 12
ellipse(x + 120, y + 120, w - 2, h -2); //star 13
ellipse(x + 145, y + 200, w, h); //star 14
ellipse(x + 500, y + 300, w, h); //star 15
ellipse(x + 200, y + 205, w - 2, h); //star 16
}
function mouseMoved() {
starB = starB + 3;
if (starB > 250) {
starB = 109;
}
}
function mousePressed() {
if ( moonR === 236) {
moonR = 252;
} else {
moonR = 236;
}
if ( moonG === 236) {
moonG = 234;
} else {
moonG = 236;
}
if ( moonB === 236) {
moonB = 109;
} else {
moonB = 236;
}
if ( moonR2 === 109) {
moonR2 = 252;
} else {
moonR2 = 109;
}
if ( moonG2 === 110) {
moonG2 = 234;
} else {
moonG2 = 110;
}
if ( moonB2 === 106) {
moonB2 = 109;
} else {
moonB2 = 106;
}
if ( bckgrndR === 37) {
bckgrndR = 108;
} else {
bckgrndR = 37;
}
if ( bckgrndG === 21) {
bckgrndG = 214;
} else {
bckgrndG = 21;
}
if ( bckgrndB === 66) {
bckgrndB = 251;
} else {
bckgrndB = 66;
}
if ( starR === 252) {
starR = bckgrndR;
} else {
starR = 252;
}
if ( starG === 234) {
starG = bckgrndG;
} else {
starG = 234;
}
if ( starB === 109) {
starB = bckgrndB;
} else {
starB = 109;
}
}
This was fun! Move your mouse to make the stars twinkle and create a shooting star, and if the night isn’t your thing, click to turn the scene to daytime! It was tough juggling a lot of elements and variables, but I think this is quaint and I feel like I learned a lot twiddling with the different mouse functions.