Reversing a while loop animation?
in
Programming Questions
•
1 year ago
I've been trying to figure out how to make this sine wave animation go backwards smoothly after it hits the bottom of the processing window. I've tried a while loop that decreases 'y' by 1 when 'y' is greater than height, but it just gets frozen. I basically want the animation to go up/down smoothly. How can I make the animation go in reverse when it reaches the bottom and vice versa?
- float time = 0;
- void setup() {
- size(550, 550);
- // smooth();
- background(100, 200, 50);
- }
- void draw() {
- background(#B72C2C);
- stroke(#F7EBEB);
- float x = 0;
- float y = 0;
- while (x< width) {
- stroke(255);
- y = 10 +10*sin(x/20 )*time;
- point(x, y );
- x = x + .1;
- }
- time = time +.5;
- println(y);
- println(time);
- }
1