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 › draw() and refreshing drawn objects
Page Index Toggle Pages: 1
draw() and refreshing drawn objects (Read 405 times)
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);
 
}

------------------------------------------------------------
Re: draw() and refreshing drawn objects
Reply #1 - May 15th, 2006, 11:02pm
 
Just add
background(0,0,0); to the start of draw, that'll clear the display, and fill it with black.
Re: draw() and refreshing drawn objects
Reply #2 - May 15th, 2006, 11:05pm
 
That'll do it.  Geez...I'm disappointed I didn't just post the question in the first place.  Thanks a lot for your help.
Page Index Toggle Pages: 1