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

LinearInterpolator

      
Search:  
 
 
import Numeric
 
def linear_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 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)
    stop_second = inc * 2
    while seconds > stop_second:
        seconds -= inc
        current += step
        yield tuple(current)
    yield tuple(stop)

Comments
After playing around with this a little bit I noticed that there are several things needing improvement. The first is on line 13, which should read:
step = diff * inc / seconds
to properly factor in the desired timeframe. The second is the handling of seconds and stop_second. The latter is actually completely unnecessary and can be replaced with inc.

-- 23 April 2007 Duoas



page migrated to new wiki
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Feb 4, 2016

Jan 30, 2016

Jan 24, 2016

Jan 23, 2016

Jan 18, 2016

Jan 5, 2016


Dec 27, 2015

Dec 12, 2015

Dec 11, 2015

Dec 7, 2015

Nov 17, 2015

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