We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Help with a clock
Page Index Toggle Pages: 1
Help with a clock (Read 1144 times)
Help with a clock
Oct 29th, 2009, 11:00am
 
I'm sure theres actually a VERY simple explaination of how to do this, but I've only started using processing a few days ago, so this is all very new to me [its for a school project so I've been thrown in the deep end].

This is what I'm trying to do:
I'm making a clock which displays the time according to how people say it, eg "5 o'clock", "half past 4". I've been given the code for a "digital" clock so I pressume its just a task of adding if variables...

Any help would be very much appreciated!

PFont myfont;

void setup() {
// To create a font for use in processing, save your program and then use Tools/font
// The font file will be saved in the sketch's "data" directory
size (250,100);
  background(100,100,100);

myfont = loadFont("Arial-ItalicMT-48.vlw");
textFont(myfont);
}

void draw() {
 background(100,100,100);
 
 int s = second();
 int m = minute();
 int h = hour();
 
 text(h+":"+m+":"+s, 15, 50);
}
Re: Help with a clock
Reply #1 - Oct 29th, 2009, 11:43am
 
Right, for example you could start with:
if ((h==12) && (m==0)) text("noon", 15, 50);
else text(h+":"+m+":"+s, 15, 50);
Re: Help with a clock
Reply #2 - Oct 29th, 2009, 11:56am
 
ah yes! that works. Thank you very much Ben!

Next problem is getting rid of the numbers so they dont show up...
Any ideas?
Re: Help with a clock
Reply #3 - Oct 29th, 2009, 12:03pm
 
Sure thing --

if you mean the text(h+":"+m+":"+s, 15, 50); -- those are your numbers, so you can just comment // that line out...

text(h+":"+m+":"+s, 15, 50); // is saying:
draw this text:  hour-number plus a colon, plus the minute number plus another colon, plus the seconds -- at location (15,50).
Re: Help with a clock
Reply #4 - Oct 29th, 2009, 12:12pm
 
Ben, you are my saviour! I think I've gotten the jist of how this is going to work now.

Thank you very very much for your time!
Page Index Toggle Pages: 1