Loading...
Logo
Processing Forum
Please bear with me, I'm new to programming.

I want to trigger a one second animation once the mouseX is greater than 100.

I've added a "for" loop to generate the animation, but I see that you cannot see the transition in a for loop. I can only see the start and end.

How can I animate the ball (code below) from ellipse(20,20,20,20) to ellipse(400,400,400,400) and be able to see the transition?

Thanks so much!!!



Copy code
  1. void setup(){
  2.  
  3.   size(400,400);
  4.   smooth();
  5.  
  6. }
  7. void draw(){
  8.  
  9.   background(0);
  10.  
  11.   if (mouseX > 100) {                //Once mouse gets to 100, begin animation.
  12.    
  13.   for (int i=20; i<400; i++){        //Animate ball
  14.   ellipse(i,i,i,i);
  15.   }
  16.    
  17.   } else {
  18.    
  19.   ellipse(20,20,20,20);
  20. }
  21. }

Replies(7)

Perhaps have a look at the Technical FAQ, particularly the third entry...
Thanks phi.lo, for the link.

This is confusing for me because I am animating processing shapes not images.

Do you know of another tutorial, or sample code you could point me to?


Thanks!


Image or shapes, same things. Just remplace image() call by rect(), eliipse() or whatever. The important part is about loops inside draw() just don't work as expected by lot of new users. Relevant part is " all drawing operations done within draw() are cumulated, and only the end result is displayed when draw() exits"
Now, if the explanations are not clear, perhaps you can point out where, so I can improve these articles.
Thanks again,

I've got the following, but it doesn't seem to animate. Do you see where i've gone wrong?

Thanks for your help.

Copy code
  1. int counter; // Automatically initialized at 0
  2. final int DISPLAY_TIME = 2000; // 2000 ms = 2 seconds
  3. int lastTime; // When the current image was first displayed
  4.  
  5. void setup()
  6. {
  7.   size(500, 500);
  8.  
  9.  
  10.   lastTime = millis();
  11. }
  12.  
  13. void draw()
  14. {
  15.   background(255);
  16.   fill(#005599);
  17.   text(frameCount, 10, 20); // Shows the sketch isn't stopped between each image
  18.  
  19.   if (millis() - lastTime >= DISPLAY_TIME) // Time to display next image
  20.   {
  21.     // Increment counter, then compute its modulo, ie. reset it at zero when reaching images.length
  22.     counter = ++counter;
  23.     lastTime = millis();
  24.   }
  25.   ellipse(counter,counter, 50, 50);
  26. }
Oh wait! I think I got it.

What if I want a 2 second animation to run once the mouseX gets above 200, even if the mouseX is only above 200 for 1 second.


Thanks, this is a huge help.


Copy code
  1. int counter; // Automatically initialized at 0
  2. final int DISPLAY_TIME = 2000; // 2000 ms = 2 seconds
  3. int lastTime; // When the current image was first displayed
  4.  
  5. void setup()
  6. {
  7.   size(500, 500);
  8.   fill(#005599);
  9.  
  10.  
  11.   lastTime = millis();
  12.  
  13.   print(lastTime);
  14. }
  15.  
  16. void draw()
  17. {
  18.  
  19.  
  20.  
  21.  
  22.  
  23.   if (millis() - lastTime >= DISPLAY_TIME) // Time to display next image
  24.   {
  25.     counter = counter+5;
  26.     lastTime = millis();
  27.   }
  28.  
  29.       ellipse(counter,counter, counter, counter);
  30. }


Copy code
  1. int counter; // Automatically initialized at 0
  2. final int DISPLAY_TIME = 2000; // 2000 ms = 2 seconds
  3. int lastTime; // When the current image was first displayed
  4. boolean bAnimate;

  5. void setup()
  6. {
  7.   size(500, 500);
  8.   fill(#005599);

  9.   smooth();
  10. }

  11. void draw()
  12. {
  13.   background(0);
  14.   if (mouseX > 100 && !bAnimate)
  15.   {
  16.     bAnimate = true;
  17.     lastTime = millis();
  18.   }

  19.   if (bAnimate)
  20.   {
  21.     counter += 5;
  22.     ellipse(counter, counter, counter, counter);
  23.     if (millis() - lastTime >= DISPLAY_TIME) // Time to display next image
  24.     {
  25.       bAnimate = false;
  26.       counter = 0;
  27.     }
  28.   }
  29. }

phi.lho- Thank you very, very much!!!!

I'm studying this code and i'm starting to understand! Thanks you again!


C