sketchDownload
// Ilia Urgen
// Section B
// iurgen@andrew.cmu.edu
// Project-06
function setup() {
createCanvas (450,450);
}
function draw() {
// 0:00 to 8:00
if (hour() >= 0 & hour() <= 8) {
sleep();
}
// 8:00 to 20:00
else if (hour() >= 8 & hour() <= 20) {
daytime();
}
// 20:00 to 24:00
else if (hour() >= 20 & hour() <= 24) {
sleep();
}
}
// 0:00 to 8:00 and 20:00 to 24:00
function sleep() {
var s = map (minute(), 0, 60, 0, 3600) + second();
var c = map (hour(), 0, 20, 0, 70);
var h = map (s, 0, 3600, 0, 90);
color_1 = color (120,29,173);
color_2 = color (0);
// ombre
for (var y = 0; y < height; y++ ) {
n = map (y,0, height, 0, 1);
var color_3 = lerpColor (color_1, color_2, n);
stroke (color_3);
line (0, y, width, y);
}
stroke (0);
strokeWeight (8);
// canvas border lines
line (1,1,1,449);
line (1,1,449,1);
line (1,449,449,449);
line (449,1,449,449);
// window
fill (11,11,10 + c);
rect (width/2, height/2 - 180, 200, 200);
// moon
noStroke();
fill (230,230,180);
ellipse (320,120,100,100);
fill (11,11,10 + c);
ellipse (375 - h,120,95,110);
// bed
fill (152,118,84);
strokeWeight (0.5);
rect (width/2 - 200, height/4 + 210, 300, 100);
rect (width/2 - 200, height/4 + 310, 40, 40);
rect (width/2 + 60, height/4 + 310, 40, 40);
// hair on head
fill (255);
ellipse (280,315,100,40);
// pillow
fill (0);
ellipse (280,300,70,45);
//blanket
strokeWeight (2);
fill (123,24,26);
square (width/2 - 200, height/4 + 170, 50);
square (width/2 - 150, height/4 + 220, 50);
square (width/2 - 100, height/4 + 170, 50);
square (width/2 - 50, height/4 + 220, 50);
square (width/2, height/4 + 170, 50);
square (width/2 - 200, height/4 + 270, 50);
square (width/2 - 100, height/4 + 270, 50);
square (width/2, height/4 + 270, 50);
fill (0,65,169);
square (width/2 - 200, height/4 + 220, 50);
square (width/2 - 150, height/4 + 170, 50);
square (width/2 - 100, height/4 + 220, 50);
square (width/2 - 50, height/4 + 170, 50);
square (width/2, height/4 + 220, 50);
square (width/2 - 150, height/4 + 270, 50);
square (width/2 - 50, height/4 + 270, 50);
// Flickering Zzz's
zzz();
}
function zzz() {
if (second () % 2 == 0) {
stroke (255);
strokeWeight (4);
line (280,270,320,270);
line (280,230,320,230);
line (280,270,320,230);
push();
translate (40, -20);
line (280,270,320,270);
line (280,230,320,230);
line (280,270,320,230);
pop();
push();
translate (80, -40);
line (280,270,320,270);
line (280,230,320,230);
line (280,270,320,230);
pop();
}
}
// 8:00 to 20:00
function daytime () {
var s = map (minute (), 0, 60, 0, 3600) + second();
var m = floor (map (minute (), 2, 60, 2, 10));
var x = map (s, 0, 3600, 0, 340);
var c = map (hour (), 3, 20, 0, 100);
color_1 = color (25,206,255 - m);
color_2 = color (0,129,150 - m);
// ombre
for (var y = 0; y < height; y++ ) {
n = map (y,0, height, 0, 1);
var color_3 = lerpColor (color_1, color_2, n);
stroke (color_3);
line (0, y, width, y);
}
// moving clouds
noStroke();
fill (255);
circle (300 + c,120,50);
circle (300 + c,90,50);
circle (340 + c,120,50);
circle (340 + c,90,50);
circle (282 + c,105,50);
circle (358 + c,105,50);
push();
translate (72,80);
circle (300 + c,120,50);
circle (300 + c,90,50);
circle (340 + c,120,50);
circle (340 + c,90,50);
circle (282 + c,105,50);
circle (358 + c,105,50);
pop();
stroke (0);
strokeWeight (8);
// walls
noFill();
rect (width/2, height/2 - 180, 200, 200);
fill (255,127,80);
noStroke();
rect (0, height/6 - 80, 221, 260);
rect (height/2 - 12, 0, 240, 41);
rect (0, height/2 + 24, width, 202);
rect (height/2 + 204, 0, 22, 300);
// countertop
fill (255);
rect (0,width/2 + 24, width, 30);
// cabinets
fill (86,60,40);
rect (0,width/2 + 48, width, 200);
stroke (0);
noFill();
strokeWeight (2);
rect (28,width/2 + 72, 80, 140);
rect (132,width/2 + 72, 80, 140);
rect (236,width/2 + 72, 80, 140);
rect (340,width/2 + 72, 80, 140);
// doorknobs
noStroke();
fill (212,175,55);
circle (90,330,20);
circle (150,330,20);
circle (300,330,20);
circle (360,330,20);
strokeWeight (8);
// canvas border lines
line (1,1,1,449);
line (1,1,449,1);
line (1,449,449,449);
line (449,1,449,449);
// "GOOD"
if (second () % 2 == 0) {
push();
translate (20,40);
stroke (0);
strokeWeight (4);
line (20,20,40,20);
line (20,20,20,60);
line (20,60,40,60);
line (40,60,40,40);
line (40,40,30,40);
line (60,20,80,20);
line (60,20,60,60);
line (60,60,80,60);
line (80,60,80,20);
push();
translate (40,0);
line (60,20,80,20);
line (60,20,60,60);
line (60,60,80,60);
line (80,60,80,20);
pop();
line (140,20,140,60);
line (140,20,160,40);
line (140,60,160,40);
pop();
}
// "DAY!!!"
if (second () % 2 == 1) {
push();
translate (20,40);
stroke (0);
strokeWeight (4);
line (20,80,20,120);
line (20,80,40,100);
line (20,120,40,100);
line (60,80,80,80);
line (60,80,60,120);
line (60,100,80,100);
line (80,120,80,80);
line (100,80,110,100);
line (110,100,120,80);
line (110,100,110,120);
line (140,80,140,110);
line (150,80,150,110);
line (160,80,160,110);
point (140,120);
point (150,120);
point (160,120);
pop();
}
}