We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My aim would be to create a counter, which starts at 0, counts up to 10, then down again to 0, and again starts from the beginning. Somehow i can not figure out how to do that:
int countdown =0;
int seconds, seconds2, startTime;
void setup() {
startTime = millis()/1000 + countdown;
}
void draw() {
seconds = startTime + millis()/1000;
if (seconds > 10) seconds = startTime - millis()/1000;
if (seconds < 0) seconds = startTime + millis()/1000;
println (seconds);
}
Answers
https://Forum.Processing.org/two/discussion/23846/time-delay-in-python-mode#Item_11
http://Bl.ocks.org/GoSubRoutine/1a0d21828319cf18fecf44101764bd60
Conceptually your counter is a bouncing ball. Just like a ball might have a direction vector, and any collision with a wall causes the vector to switch direction....
This will "bounce."
Yes, perfect! Bouncing-Ball, have not thought about that!
...now thinking further, would it be possible to increase the "limit" (in this case 10) always with 1, if reached? f.e. in the 2nd pass to 11, the 3rd pass to 12,...
sure in line 7 replace 10 with upperBound
After line 8 say upperBound++;
Before setup ():
int upperBound=10;
thank you, actually simple. i think i'm starting to understand loops...
i "remapped" the number-range starting at 90, counting up and down. now i wonder how to set limits, f.e. at 130 (50 when counting down), where the loops resets to the starting position. or even better, shrink the range again down. i guess it is another if situation inside the existing one, or?
That's right
In line 16 you see ++
replace this by upperBound += upperBoundStep;
Then similar to line 14 say
if (upperBound> 130)
upperBoundStep = -1;
thanks for your fast answers! i don't understand it completely:
Basically the upperBound value dows the same as the x value:
It behaves like a ball that gets reflected
In line 5
upperBoundStep=1;
upperBound changes very very slowly at the moment, only when x touches it (line 14-16)
or use sinus