pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Wiki

SmoothInterpolator

      
Search:  
 
 
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
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Dec 16, 2014


Dec 14, 2014

Dec 9, 2014

Dec 6, 2014

Dec 5, 2014

Dec 3, 2014

Nov 27, 2014


Nov 13, 2014

Nov 11, 2014


... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)