johnny
YaBB Newbies
Offline
Posts: 7
draw() and refreshing drawn objects
May 15th , 2006, 10:51pm
Hi, New to Processing and Java programming. To learn, I'm trying to build a simple clock app. My problem, as you'll see by running the code below, is that the draw() function loops continuously and draws the time values overtop of each other in the display. I know that this is exactly how it's supposed to work...but it's not what I'm trying to do, of course! How do I set up my code so that the time variables are continually refreshed based on the computer clock, but only the most recent value for each is drawn/visible? I'm sure this is an elementary mistake, but I can't figure out a solution using the Reference guide. Is there some sort of refresh or reset that needs to go at the bottom of the loop? All help is appreciated. Once I get my head around this, I think I'll be able to make a lot more progress (process?). ------------------------------------------------------------ /* SETUP ENVIRONMENT */ void setup() { //set size of display to 300x300 size(300,300); //set background colour to dark gray background(60); //set display to anti-alias smooth(); //set framerate to 1fps framerate(1); //FONT VARIABLES //set text colour to white fill(255); //load a new font PFont Helvetica = loadFont("HelveticaNeue-Light-16.vlw"); // set the font and its size (pixels) textFont(Helvetica, 12); //LABELS text("HOUR", 10, 15); text("MINUTE", 10, 30); text("SECOND", 10, 45); text("DAY", 10, 75); text("MONTH", 10, 90); text("YEAR", 10, 105); } /* OUTPUT DATA */ void draw() { //TIME VARIABLES int time_h = hour(); int time_m = minute(); int time_s = second(); int time_d = day(); int time_mth = month(); int time_y = year(); //OUTPUT TIME text(time_h, 70, 15); text(time_m, 70, 30); text(time_s, 70, 45); text(time_d, 70, 75); text(time_mth, 70, 90); text(time_y, 70, 105); } ------------------------------------------------------------