I am looking for some sorta time command in processing. I have a message box (messages from the robot to the computer) and I want to show a text message for say, 5 seconds or so then have it clear off. I want to do the same thing for an image --show the image for a given time, then remove it. I.e. if the robot is charging, I would like to show a simple 3-image "animation" (each image showing for a second or two) --think of the bars clicking by when your mobile is charging.
Bottom line: I would like to display "something" then remove it. Any thoughts?
****Update****
This post has morphed a bit into the idea of "clearing" text --I wanted to figure out the "proper" way of doing this and was a bit surprised at the answer. --there is no clear text command. Everything is simply based on processing "redrawing" the sketch each time through the loop. --So really there is no text like there is no cold, only a lack of heat. There is no text clear, just a lack of writing it. The text is already cleared!. If you want to remove text, just stop writing it. If the text command has to stay in a part of the code that you can't turn off and on for some reason, I wrote this clunky way of doing it --set a little backdrop box for the text to sit on top of. Then redraw the box on top of the text to clear it. --Also, I should say that when I said "where you can't turn it on or off", this is assuming the use or non use of the background command. The example below will show a text box with blinking text without the use of the background command to clear the whole window.
PFont myFont;
boolean onoff = false;
void setup(){
size (200,200);
background(0);
myFont = loadFont("AgencyFB-Reg-48.vlw");
}
void draw()
{
fill (100);
rect (50,height/2-16,100,20);
if (onoff){
fill(255);
textFont(myFont, 14);
text("Hello World",55,height/2);
onoff=false;
} else {
fill (100);
rect (50,height/2-16,100,20);
onoff=true;
}
delay (1000);
}
I’m not familiar with
I’m not familiar with processing, but you showed something with the RGB mixer, where you used a sleep() command.
Wont that work here?
If you don’t want you program to “sleep” while the time goes by, you could check what the time is, in your main program loop. First save what time you showed the picture/message, and then, when the time is 5 seconds later, remove the picture/message.
You could also initiate a new thread, that just keeps track of this message, but that is a little harder to accomplish, and i have no idea if processing can do that.
More code –
Here is the same thing using second() and the computer’s clock. I have to say I still think doing it this way is very clunky but it works.
PFont myFont;
int holdsecond=0;
boolean onoff=false;
void setup(){
size (200,200);
background(0);
myFont = loadFont(“AgencyFB-Reg-48.vlw”);
fill (100);
rect (50,height/2-16,100,20);
holdsecond=second();
}
void draw()
{
if (second()==holdsecond+2 & onoff==true){
println (“It was true now it is false”);
holdsecond=second();
onoff=false;
}
if (second()==holdsecond+2 & onoff==false){
println (“It was false now it is true”);
holdsecond=second();
onoff=true;
}
if (onoff){
fill(255);
textFont(myFont, 14);
text(“Hello World”,55,height/2);
} else {
fill (100);
rect (50,height/2-16,100,20);
}
}
Alright boys! Done!
Figured out how to show an image or text for a given amount of time then let it clear itself. I even fixed the problem of the >59 seconds overflow problem. Yeah!
PImage Batt0;
PImage black;
PFont myFont;
int holdsecond=second();
int howlongtoshow=10; //how long to show the image/text (seconds)
boolean onoff = false;
void setup(){
size (400,400);
myFont = loadFont (“AgencyFB-Reg-48.vlw”);
Batt0 = loadImage(“Batt0.JPG”);
}
void draw(){
background(0);
if (onoff==true){
image(Batt0,200,20);
fill (255);
textFont(myFont, 18);
text (“Hello World”,200,200);
}
if (second()==holdsecond){
//image(black,200,20); this would replace the backdrop rect
onoff=false;
}
println (second());
println (holdsecond);
}
void keyPressed(){
onoff=true;
if (second()>59-howlongtoshow){
holdsecond=howlongtoshow+second()-60;
}else{
holdsecond=second()+howlongtoshow;
}
println (“key pressed”);
}