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 › Need assistance with displaying text.....please
Page Index Toggle Pages: 1
Need assistance with displaying text.....please (Read 844 times)
Need assistance with displaying text.....please
Nov 6th, 2009, 5:43am
 
If you review the attached code,  in the "draw" routine, where I am writing the value of 'n' to the display window,  you will notice that I am trying to "blank" the same area before each display update of "n".  I can NOT get this to work.  It simply displays all the values on 'n' one on top of the other,  resulting in a mess.

Can someone point out my errors,  and how I can get the countdown 'n' to display cleanly?

NOTE:  I had to remove the http links to the actual images in the "loadImage" code below,  as I have not made enough posts here for the system to allow to include active links.

Code:

// Declare all the variables

int refreshTime = 30 * 1000;  // every 15 minutes;
int lastTime;
String blank = "    ";
PFont font;
PImage b;
PImage bb;
PImage cc;
PImage dd;


void setup() {
 size(500,330);
 frameRate(1);
 font = loadFont("Futura-MediumItalic-48.vlw");
 fill(120);
 textFont(font,18 );
 delay(10*1000);  // delay to wait for Arduino bootloader, just in case
 lastTime = millis() - refreshTime; // make it so we getWebImages at startup
}

void draw() {
 int n = (int)((refreshTime-(millis()-lastTime))/1000)+1;
 println("countdown to update: "+ n);
 text(blank, 45, 41);
 text(n , 45, 41);
 if( millis() - lastTime >= refreshTime ) {
   getWebImages();
   lastTime = millis();
 }
}

void getWebImages() {
 println("Fetching images....");
 b=loadImage("image1");
 bb=loadImage("image2");
 cc=loadImage("image3");
 dd=loadImage("image4");
 
//Display the images  
 println("Displaying Images.....");
 image(b,120,0);
 image(bb,0,0);
 image(cc,0,49);
 image(dd,0,70);
 
 return;
}  
 catch (Exception ex) {
   ex.printStackTrace();
   System.out.println("ERROR: "+ex.getMessage());
 }

}


Thanks for any help....

Jim
Re: Need assistance with displaying text.....please
Reply #1 - Nov 6th, 2009, 6:14am
 
try:

Quote:
void draw() {
 background(0);
 // ...your code (but don't bother with the text(blank...)
}


As you've discovered without a call to background() or some other method of clearing the screen, each draw cycle draws on top of the previous...
Re: Need assistance with displaying text.....please
Reply #2 - Nov 6th, 2009, 6:31am
 
Thanks, Blindfish,  and yes I've tried that. But it clears the entire display window,  and all I'm trying to do is clear or 'blank' just the small section that the 'n' variable is written to.

I do appreciate your reply, though.....

Jim
Re: Need assistance with displaying text.....please
Reply #3 - Nov 6th, 2009, 6:48am
 
In which case the same principle applies: i.e. "some other method of clearing the screen" (though perhaps 'clearing' wasn't the best way of wording that).

You could just draw a rect() over the relevant portion of the screen before drawing the new text...

Also don't forget that things are drawn to the screen in the order that they appear in draw().  So if those images are meant to be a background you'd want to draw them before applying the text.

(Also note that to improve performance you should load images in setup() not draw().  That way you aren't re-loading each image each frame; though to be fair in a 1fps sketch it's not as much of an issue.)
Re: Need assistance with displaying text.....please
Reply #4 - Nov 6th, 2009, 6:50am
 
Blindfish,

Thank you again!  I will get busy now and try your suggestions,  and then I will either post a success,  or will ask more questions !  I'm trying to learn !!

Jim
Re: Need assistance with displaying text.....please
Reply #5 - Nov 6th, 2009, 12:57pm
 
Blindfish,

Things are working great now.  I took your suggestion and implemented in the code below.....thank you very much.

Code:
// Declare all the variables
String urlstr = "http://jdmartin.x10hosting.com/parsed%20color.txt";
String urlstr2 = "http://jdmartin.x10hosting.com/parsing.php";
int refreshTime = 900 * 1000;  // every 15 minutes;
int lastTime;
String blank = "    ";
PFont font;
PImage b;
PImage bb;
PImage cc;
PImage dd;


void setup() {
 size(500,330);
 frameRate(1);
 font = loadFont("Futura-MediumItalic-48.vlw");
 fill(153);
 textFont(font,15 );
 delay(10*1000);  // delay to wait for Arduino bootloader, just in case
 lastTime = millis() - refreshTime; // make it so we getWebImages at startup
}

void draw() {
 int n = (int)((refreshTime-(millis()-lastTime))/1000)+1;
 println("countdown to update: "+ n);
 fill(200);
 rect(0, 20, 120, 28);
 fill(0);
 text("update in: "+n+"s", 5, 41);
 if( millis() - lastTime >= refreshTime ) {
   getWebImages();
   lastTime = millis();
 }
}

void getWebImages() {
 println("Fetching images....");
 b=loadImage("http://www.gedds.alaska.edu/AuroraForecast/images/Scale1.GIF");
 bb=loadImage("http://www.n3kl.org/sun/images/status.gif");
 cc=loadImage("http://www.n3kl.org/sun/images/kpstatus.gif");
 dd=loadImage("http://www.gedds.alaska.edu/AuroraForecast/images/NorthAmerica_1.png");
 
//Display the images  
 println("Displaying Images.....");
 image(b,120,0);
 image(bb,0,0);
 image(cc,0,49);
 image(dd,0,70);
 
 return;
}  
 catch (Exception ex) {
   ex.printStackTrace();
   System.out.println("ERROR: "+ex.getMessage());
 }

}
Page Index Toggle Pages: 1