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 & HelpPrograms › math/syntax question about animating equations
Page Index Toggle Pages: 1
math/syntax question about animating equations (Read 212 times)
math/syntax question about animating equations
Feb 9th, 2009, 2:06am
 
my brain is fried.  can someone tell me if i'm doing this the best way:

i'm animating a fairly complicated set of mathematical shapes.  but let's just say i'm animating two equations.  they are calculated in terms of time t (seconds).  because i'm drawing at 30fps, t is advanced by 1/30 each frame.

i have a visual timeline with a moving dot showing t, and when t gets to the loop point, it's set back to 0, and the dot goes back to the start.

i want the option to freeze either equation without stopping t.  one approach is to subtract a "phase" variable, an offset, from t when the equation is calculated.  this phase would have to increment along with t every frame.  phase has to stop incrementing when it reaches the specified freeze duration.

the loop point must also be extended by the freeze duration.  for example, if the equation used to loop every 5 seconds, and the freeze happens at time X, and has a duration of 1 second, the loop point becomes 5+1 = 6 (regardless of when the freeze happens).   this processing example demonstrates this working:

Code:

float tLoop = 5.0;

// time of loop
float tFreeze = 2.0;

// time of freeze
float freezeDur = 1.0;

// duration of freeze
float phase = 0.0;

// equation offset
float t = 0.0;

// time (sec.)

void setup() {
frameRate(30);
}

void draw() {
equation(t-phase);

if (t > tFreeze) {
if (phase < freezeDur) phase += 1/30.0;
}

t += 1/30.0;

if (t > tLoop+freezeDur) {
phase = 0;
t = 0;
}
}

void equation(float _t) {
// draw something based on offset time
}



so, my question is, a) am i doing this most efficient way, and b) how do i handle having multiple freeze points?  i didn't want to clutter up the example code above, but i have 2 equations and a 2D array of freeze times.  (i thankfully have already figured out to calculate a new total loop point by finding the Least Common Multiple of each equation's adjusted loop point.)

here's a visual example that works for one freeze point, but i just need some help incrementing through multiple freeze points.

http://www.openprocessing.org/visuals/?visualID=996

thanks doods.

- e
Page Index Toggle Pages: 1