Digital Clock on Computer
in
Share your Work
•
1 year ago
Hello!
I would like to share a simple digital clock I made on the computer. I haven't used Processing so much, so all my programs are simple! To use, it copy the code to the IDE, save it, then create a font named "CourierNewPSMT-48.vlw". It even has some greetings! You can easily add your own greatings. Keep in mind that the mon variable is actually month()-1, because I use it to access an array. Here is the code:
- PFont font;
void setup(){
size(500,350, P2D);
}
void draw(){
String mois[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int mon = month()-1;
mon = constrain(mon, 0, 11);
int date = day();
int yr = year();
int sec = second();
int mins = minute();
int hr = hour();
String m = " a.m.";
String om = "";
String o = "";
if (hr >= 12) m = " p.m.";
else m = " a.m.";
if (mins < 10) om = "0";
else om = "";
if (sec < 10) o = "0";
else o = "";
String time = hr+":"+mins+":"+sec+m;
String d = mois[mon] + " " + date + ", " + yr;
String msg = "";
background(0);
if (hour() > 12) hr-=12;
else hr = hour();
time = hr + ":" + om + mins + ":" + o +sec + m;
//if (mon == 2 && date == 25) msg = "Happy Birthday, Daniel!";
if (mon == 11 && date == 25) msg = "Merry Christmas!";
else if(mon == 0 && date == 1) msg = "Happy New Year";
else if (hour() >= 0 && hour() <= 11) msg = "Good Morning!";
else if (hour() >= 12 && hour() <=18) msg = "Good Afternoon!";
else if (hour() >=19 && hour() <=23) msg = "Good Evening!";
fill(0, 200, 0);
String t = "TimesNewRomanPSMT-48.vlw";
String c = "CourierNewPSMT-48.vlw";
font = loadFont(t);
textFont(font);
textMode(SCREEN);
textAlign(CENTER);
text(time, width/2, height/3);
textAlign(CENTER);
textMode(MODEL);
textFont(font, 34);
text(d, width/2, height/2);
textAlign(CENTER);
textMode(MODEL);
textFont(font, 30);
text(msg, width/2, (height - height/3));
}
Please give me some comments on this clock!