We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › jumping between frames in an animated sequence
Page Index Toggle Pages: 1
jumping between frames in an animated sequence (Read 1024 times)
jumping between frames in an animated sequence
Feb 18th, 2010, 7:30pm
 
This is my first Processing project, so forgive me if this is a dumb question.

I'm creating an animation where each frame consists of a series of lines and text. Each frame is pretty simple. The position of lines etc can be calculated from the frame's position in the animation sequence.

As the animation runs, a circle will move along a timeline at the base of the screen so the user can see how far the animation has progressed. I want users to be able to click on the circle and move the animation backwards or forwards.

I'm wondering how to draw each frame so that Processing can draw each as quickly as possible. I can see two options:

1. Check the position on the timeline and use that position to generate a new frame each time.
2. Draw all frames before running the animation, save each as an image and use image() to display the appropriate frame based on the timeline position.

Which method would be more likely to make the animation look smooth as the user dragged the timelines\ backwards and forwards?

Thanks!

Jim
Re: jumping between frames in an animated sequence
Reply #1 - Feb 19th, 2010, 1:08am
 
I'd go with option 1, considering that the frame is redrawn every time draw() is called anyway. Consider the code below. Variable xx and yy are each, essentially, frame counters for lines. Depending on where you click determines where the lines are, and when you release the mouse button they "play" through the "frames" in order.

int xx = 0;
int yy = 0;
void setup(){
 size(200,200);
 stroke(255);
}
void draw(){
 background(0);
 xx=(++xx)%width;
 yy=(++yy)%height;
 line(0,yy,width,yy);
 line(xx,0,xx,height);
 if(mousePressed){
   xx = mouseX;
   yy = (mouseY+height/2)%height;
 }
}
Re: jumping between frames in an animated sequence
Reply #2 - Feb 25th, 2010, 9:23am
 
Thanks, TfGuy44.

If the code that defines each frame were more complex, presumably there comes a point at which it is quicker to load all the frames in advance and use image() to display the appropriate one?

jim
Re: jumping between frames in an animated sequence
Reply #3 - Feb 25th, 2010, 3:56pm
 
Presumably, yes.
But that extra speed comes at the rather extreme cost of using up a lot of memory.
Re: jumping between frames in an animated sequence
Reply #4 - Mar 6th, 2010, 6:34pm
 
if your animations have somewhat of a defined end position then you could use my animation library which i post at http://processing.org/discourse/yabb2/num_1261940382.html. you can see an example of creating tweens and seeking through them using timeline class http://ekeneijeoma.com/processing/motionlib/examples/Timeline_Seek/applet/index.... or the tweensequence class http://ekeneijeoma.com/processing/motionlib/examples/TweenSequence_Seek/applet/i...
Page Index Toggle Pages: 1