|
/* |
|
* us p5.js to draw a clock on a 960x500 canvas |
|
*/ |
|
|
|
//local copy ** |
|
var CanVasHeight = 500; |
|
var CanVasWidth = 960; |
|
var alarmVal = 0; |
|
|
|
|
|
//to do |
|
//add in the new font-BUGGED |
|
//add in background of some sorts-BUGGED |
|
|
|
function draw_clock(hour, minute, second, millis, alarm) { |
|
//de-bug for time, manual time input |
|
//min values |
|
// hour = 0; |
|
// minute = 0; |
|
// second = 0; |
|
// millis = 999; |
|
//max values |
|
// hour = 23; |
|
// minute = 59; |
|
// second = 59; |
|
// millis = 999; |
|
|
|
// background(255); |
|
textSize(50); |
|
textAlign(CENTER); |
|
text(hour + "h", 390, 375); |
|
text(minute + "m", width/2, 155); |
|
textSize(30); |
|
text(second + "s", 585, 320); |
|
textSize(20); |
|
text("h",530, 413); |
|
text("m",530, 443); |
|
text("s",530, 473); |
|
|
|
|
|
|
|
//time de-bug |
|
// text("Hour: " + hour, 10, 22); |
|
// text("Minute: " + minute, 10, 42); |
|
// text("Second: " + second, 10, 62); |
|
// text("Millis: " + millis, 10, 82); |
|
|
|
//mapping to growth and srink of octogons |
|
var hourBarWidth = map(hour, 0, 23, width/8, height/8); |
|
var minuteBarWidth = map(minute, 0, 59, width/8, height/8); |
|
var secondBarWidth = map(second, 0, 59, width/8, height/8); |
|
var millisBarWidth = map(millis, 0, 1000, width/3, height/3); |
|
|
|
//manual alarm varibles input |
|
var Ahours = Hinput.value(); |
|
var Aminutes = Minput.value(); |
|
var Aseconds = Sinput.value(); |
|
var alarmSig = false; |
|
|
|
//more de-bug |
|
//print(alarmVal); |
|
//print(alarm); |
|
//print("_______"); |
|
//print(Hinput.value()); |
|
//print(Minput.value()); |
|
//print(Sinput.value()); |
|
//print(Ahours); |
|
//print(Aminutes); |
|
//print(Aseconds); |
|
//print("_______"); |
|
|
|
var secondBarWidthChunky = map(second, 0, 60, 0, width); |
|
var secondsWithFraction = second + (millis / 1000.0); |
|
var secondBarWidthSmooth = map(secondsWithFraction, 0, 60, width/12, height/12); |
|
|
|
noStroke(); |
|
|
|
//teachers alarm code |
|
if(alarm > 0){ //alarm countdown panel |
|
var a = parseInt(alarm) |
|
fill(100,50); |
|
polygon(325, 85,50,8); |
|
fill(0); |
|
text("countdown",325, 85); |
|
text("to alarm",325, 102); |
|
text(a ,325, 117); |
|
if(alarm < 15){ //flash then the alarm = 0 |
|
fill(255,0,0); |
|
polygon(435, 250, millis, 8); |
|
} |
|
} |
|
|
|
|
|
//custom alarm code, looks for change in the input then activates the look |
|
if(Ahours != 0 || Aminutes != 0 || Aseconds != 0 || alarm > 0){ //alarm state on |
|
textSize(20); |
|
fill(153,0,0,99); |
|
polygon(630, 195,40,8); |
|
fill(0); |
|
text("alarm:", 630, 195); |
|
text("on", 630, 215); |
|
}else{ //alarm state off |
|
textSize(20); |
|
fill(153,51,0,99); |
|
polygon(630, 195,40,8); |
|
fill(0); |
|
text("alarm:", 630, 195); |
|
text("off", 630, 215); |
|
} |
|
|
|
//alarm code- my own, if all values match the actual time -trigger |
|
if(hour == Ahours && minute == Aminutes && second == Aseconds ){ |
|
alarmVal = alarmVal+1; |
|
|
|
} |
|
//main trigger for alarm |
|
if(alarmVal > 0){ |
|
fill(255,0,0); |
|
polygon(435, 250, millis, 8); |
|
} |
|
|
|
|
|
//hours |
|
fill(0,0,0,99); |
|
polygon(390, 360, hourBarWidth, 8); |
|
|
|
//minutes |
|
fill(102,102,102,90); |
|
polygon(width/2, 140, minuteBarWidth, 8); |
|
|
|
//seconds |
|
fill(51,51,51,99); |
|
polygon(585, 310, secondBarWidthSmooth, 8); |
|
|
|
//alarm cluster |
|
fill(204,102,0,99); |
|
polygon(545, 435, 50, 8); |
|
|
|
//milliseconds |
|
fill(204,102,0) |
|
scale(0.2); |
|
polygon(1520, 970, millisBarWidth, 8); |
|
|
|
|
|
} |
|
function polygon(x, y, radius, npoints) { |
|
var angle = TWO_PI / npoints; |
|
beginShape(); |
|
for (var a = 0; a < TWO_PI; a += angle) { |
|
var sx = x + cos(a) * radius; |
|
var sy = y + sin(a) * radius; |
|
vertex(sx, sy); |
|
} |
|
endShape(CLOSE); |
|
} |