What do you mean by "void"? Void is the return type of a method: if it is void, the method does not return anything, it just does what it's programmed to do. Draw is the actual name of the method. It gets called 60 times a second (by default) by the Processing applet. So if you want a method like draw, you need to call it 60 times a second as well. Just make your own:
void anotherMethod()
{
//do stuff
}
and call it when you want it to run.
It is possible to have a method in a separate thread. The easiest syntax is this:
i want to make a text "WARNING" tht flashes: ON, wait 1 second, OFF, wait 1 second and on again, and repet that...
this was what i made but is not working i dont know why...
delay() halts the whole animation thread: if you call it in draw(), it will delay everything that comes after the error() call!
calling error() inside error() means you get stuck in an infinite loop. The program will wait for this loop to finish before continuing but since it's infinite, it will never get a chance to continue...
Instead you need to find a way to swap toggle from 1 to 0 or vice versa every second, without using delay() or recursive calling. Here is what you could use for that:
millis(), returns the time from the start of the program in milliseconds
frameCount, returns the amount of times draw() was called since the start of the program
solution 1:
make a call to current time and check seconds ... for even numbers select color "A" for odd numbers select color "B".
solution 2:
If the frame rate is known, every time the "draw" function is called, you might increment a counter and whenever you like (by comparing the counter) you might change the color and reset the counter
Answers
What do you mean by "void"? Void is the return type of a method: if it is void, the method does not return anything, it just does what it's programmed to do. Draw is the actual name of the method. It gets called 60 times a second (by default) by the Processing applet. So if you want a method like draw, you need to call it 60 times a second as well. Just make your own:
and call it when you want it to run.
It is possible to have a method in a separate thread. The easiest syntax is this:
You can use a while statement to loop it:
and if you want to interrupt it with a mouse click:
Only if you register draw() into another
public class
via undocumented registerMethod():i want to make a text "WARNING" tht flashes: ON, wait 1 second, OFF, wait 1 second and on again, and repet that... this was what i made but is not working i dont know why...
in void draw() i have if toggle == 1 it will show the "WARNING" text and if roggle == 0 it wont...
Don't use delay(), it stops everything. You can do the same thing by checking millis().
Also what you are suggesting, another function that is called 60 frames per second, is not necessary. Just have draw() call your function:
There are a number of ways why this doesn't work.
Instead you need to find a way to swap toggle from 1 to 0 or vice versa every second, without using delay() or recursive calling. Here is what you could use for that:
millis()
, returns the time from the start of the program in millisecondsframeCount
, returns the amount of times draw() was called since the start of the program%
, the modulo operatorNever use delay() in Processing, unless within another thread("")!
Control FPS via frameRate(): http://processing.org/reference/frameRate_.html
Don't call a function
void
. That keyword merely means a function doesn't return anything!You shoulda told us exactly what you were looking for from the beginning!
Our 1st replies were all useless for ya!
Anyways, here's what I've come up w/ related to your current request:
Dear DzAnej,
solution 1: make a call to current time and check seconds ... for even numbers select color "A" for odd numbers select color "B".
solution 2: If the frame rate is known, every time the "draw" function is called, you might increment a counter and whenever you like (by comparing the counter) you might change the color and reset the counter
solution 3: ... and so on...
Best regards
Bernd