Project 1 Part A: Basic Animation Spline Functions
To view this content, you need to install Java from java.com

Explanation/Source

F2: Constant Acceleration and Deceleration

if (t <= .5)
  return(4*.5*t*t);
else
  return(-.5 + 2*t - .5 * 4 * (t-.5) * (t-.5));

This curve was accomplished by a simple application of the kinematic equation s = d_0 + v_0*t + (1/2)a*t^2 applied with an acceleration value of four in order to get a distance of .5 in a time of .5, and a deceleration that was equal with the time shifted back to cancel out the initial velocity.

F3: Cosine-Based Animation Curve

return(-(cos(3*t)/2.0 - .5));

This is a simple cosine-based curve with the wavelength, amplitude, and y-axis tweaked to get the proper motion.

F4: Slow Acceleration, Fast Braking

return(pow(cos(t-1),9));

We found this curve by graphing several cosine power curves until there was one that appeared to have proper shape. It was shifted left by half a period in order to make the directionality correct.

F5: Wind Up and Go

float p0=0,
      p1=-.2,
      p2=.5,
      p3=1,
      b;
      float oneminust = (1-t);
       b = p0 * oneminust*oneminust*oneminust +
          3 * p1 * t *oneminust*oneminust +
          3 * p2 * t*t * oneminust +
          p3 * t*t*t;

return(b);
Using a Bezier Curve Function Taken from Wikipedia with bezier curve control points (0, -0.2, 0.5, 1). Making the second control point negative causes the car to wind-up before crossing the screen. The last two control points--.5 and 1--ensure a smooth ride all the way across the screen.

F6: Cubic Bezier Part II

float p0=0,
       p1=.8,
       p2=.9,
       p3=1,
       b;
       float oneminust = (1-t);
        b = p0 * oneminust*oneminust*oneminust +
           3 * p1 * t *oneminust*oneminust +
           3 * p2 * t*t * oneminust +
           p3 * t*t*t;

 return(b);	
The Bezier curve control points are (0, 0.8, 0.9 1). Placing P1 near the end causes a quick acceleration. This is because the car will take the same amount of time to move from P0 to near P1 (because P1 is not generally on the curve). Putting P1 further away from P0, causes the car to move faster.

F7: Stop and Go

To make a stop and go, simply create two points that are on the same vertical line, and repeatedly smooth using "S" until the line between them is nearly vertical. The car will now stop in the middle and go again.

Resources and Credits

Source code: P1a function

Built with Processing