SmoothInterpolator — wiki
import Numeric
def smooth_interpolate(start, stop, seconds, fps=30):
"""
Given a start and stop vector (2 or 3 element tuple), and a time period
at a default 30 fps, yield a sequence of vectors which smoothly
interpolate between stop and start.
"""
start = Numeric.array(start, Numeric.Float)
stop = Numeric.array(stop, Numeric.Float)
diff = stop - start
inc = 1.0 / fps
step = diff * inc
current = Numeric.array(start)
current_second = inc
while current_second < seconds:
percent = ((seconds - current_second)) / seconds
step = diff * (1.0 - (percent * percent * (3.0 - percent * 2.0)))
yield tuple(start + step)
current_second += inc
yield tuple(stop)
page migrated to new wiki Comments
Line 13 shares the same problem as the LinearInterpolator. I had to factor in a fairly large denominator to make the step function on line 18 give me values in the proper range.
The step function produces some pretty movement, but it is not caller-modifiable. My Interpolator class gives a fairly similar movement with shape=2.2 and middle=1.0.
--23 April 2007 Duoas