Its spooky season so I decided to make a jack-o-lantern clock. With this clock the idea is that the stem counts down the seconds, every minute the knife on the table moves right and at 60 minutes the knife is far right off the screen as if someone picked it up. Every hour a line is carved into the pumpkin so it is like someone picked up the knife and made a cut the n the knife goes back to the left side of the table as if it was put back down. Every 12 hours the jack-o-lantern is fully carved! The background represents AM or PM.
var knifeX; // changes knife position by min
var stemY; // height of stem
var H; //hour
function setup() {
createCanvas(480, 480);
background(220);
}
function draw() {
H = hour();
knifeX = minute() * 8; // knife moves right every minute
stemY = -220 + second();
strokeWeight(1);
noStroke();
//set up background so that it changes from am to pm
if(H < 12){ //am
background(107, 144, 255);
fill(237, 214, 100);
circle(0, 0, 250);
} else { //pm
background(28, 37, 74);
fill(177, 179, 186);
circle(100, 55, 100);
fill(28, 37, 74);
circle(125, 55, 100);
}
//clouds
fill(255);
//right side cloud
ellipse(400, 150, 200, 30);
circle(400, 130, 50);
circle(350, 125, 75);
circle(430, 140, 25);
//left side cloud
ellipse(100, 250, 200, 30);
circle(100, 230, 50);
circle(150, 225, 75);
circle(70, 240, 25);
//table
fill(125, 90, 29);
rect(0, 350, width, height - 130);
push();
translate(240, 240); //changes to center
stem()
pumpkin();
face()
pop();
knife();
}
function pumpkin(){
stroke(214, 129, 58);
fill(245, 147, 66); //orange
ellipse(0,0, 300, 250); //pumpkin body
//pumpkin details
noFill();
strokeWeight(5)
ellipse(0, 0, 100, 250);
ellipse(0, 0, 200, 250);
}
function stem(){
//stem
noStroke();
fill(18, 102, 13);
triangle(-20, -125, 20, -125, 0, -150);
rect(-15, stemY, 30, 250)
}
function knife(){
noStroke();
fill(10);
rect(knifeX, 410, 6, 50); //knife handle
fill(100);
rect(knifeX, 370, 6, 40);
arc(knifeX, 390, 20, 40, PI/2, (PI/2)*3)
}
function face(){
H = hour()
stroke(0);
strokeWeight(5);
if (H == 1 || H == 13){ //left eye
line(-100, 0, -75, -50); // left diag
} else if (H == 2 || H == 14){
line(-100, 0, -75, -50);// left diag
line(-75, -50, -50, 0); //right diag
} else if (H == 3 || H == 15){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
} else if (H == 4 || H == 16){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
//right eye
line(100, 0, 75, -50);// right diag
} else if (H == 5 || H == 17){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
//right eye
line(100, 0, 75, -50);// right diag
line(75, -50, 50, 0); //left diag
} else if (H == 6 || H == 18){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
triangle(100, 0, 50, 0, 75, -50); // right eye
} else if (H == 7 || H == 19){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
triangle(100, 0, 50, 0, 75, -50); // right eye
//start mouth
line(-120, 30, -75 , 30); // left straight line
} else if (H == 8 || H == 20){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
triangle(100, 0, 50, 0, 75, -50); // right eye
//start mouth
line(-120, 30, -75 , 30); // left straight line
//tooth left
line(-75 , 30, -75 , 50);
line(-75, 50, -25, 50);
line(-25, 30, -25, 50);
} else if (H == 9 || H == 21){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
triangle(100, 0, 50, 0, 75, -50); // right eye
//start mouth
line(-120, 30, -75 , 30); // left straight line
//tooth left
line(-75 , 30, -75 , 50);
line(-75, 50, -25, 50);
line(-25, 30, -25, 50);
// middle straight line
line(-25, 30, 25, 30);
} else if (H == 10 || H == 22){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
triangle(100, 0, 50, 0, 75, -50); // right eye
//start mouth
line(-120, 30, -75 , 30); // left straight line
//tooth left
line(-75 , 30, -75 , 50);
line(-75, 50, -25, 50);
line(-25, 30, -25, 50);
// middle straight line
line(-25, 30, 25, 30);
//tooth right
line(75 , 30, 75 , 50);
line(75, 50, 25, 50);
line(25, 30, 25, 50);
} else if (H == 11 || H == 23){
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
triangle(100, 0, 50, 0, 75, -50); // right eye
//start mouth
line(-120, 30, -75 , 30); // left straight line
//tooth left
line(-75 , 30, -75 , 50);
line(-75, 50, -25, 50);
line(-25, 30, -25, 50);
// middle straight line
line(-25, 30, 25, 30);
//tooth right
line(75 , 30, 75 , 50);
line(75, 50, 25, 50);
line(25, 30, 25, 50);
// right straight line
line(120, 30, 75 , 30);
}else{
fill(0);
triangle(-100, 0, -50, 0, -75, -50); // left eye
triangle(100, 0, 50, 0, 75, -50); // right eye
//start mouth
line(-120, 30, -75 , 30); // left straight line
//tooth left
line(-75 , 30, -75 , 50);
line(-75, 50, -25, 50);
line(-25, 30, -25, 50);
// middle straight line
line(-25, 30, 25, 30);
//tooth right
line(75 , 30, 75 , 50);
line(75, 50, 25, 50);
line(25, 30, 25, 50);
// right straight line
line(120, 30, 75 , 30);
//whole mouth
arc(0, 30, 240, 120, 2 * PI, PI);
fill(245, 147, 66)
noStroke();
rect(-75 , 25, 50, 20);
rect(25, 25, 50, 20);
}
}