Mercurial > touhou
diff pytouhou/utils/interpolator.py @ 13:58bc264aba38
Refactor
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Fri, 05 Aug 2011 13:23:33 +0200 |
parents | |
children | 6ebf9539c077 |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/pytouhou/utils/interpolator.py @@ -0,0 +1,36 @@ +class Interpolator(object): + def __init__(self, values=()): + self.values = tuple(values) + self.start_values = tuple(values) + self.end_values = tuple(values) + self.start_frame = 0 + self.end_frame = 0 + + + def set_interpolation_start(self, frame, values): + self.start_values = tuple(values) + self.start_frame = frame + + + def set_interpolation_end(self, frame, values): + self.end_values = tuple(values) + self.end_frame = frame + + + def set_interpolation_end_frame(self, end_frame): + self.end_frame = end_frame + + + def set_interpolation_end_values(self, values): + self.end_values = tuple(values) + + + def update(self, frame): + if frame >= self.end_frame: + self.values = tuple(self.end_values) + self.start_values = tuple(self.end_values) + self.start_frame = frame + else: + truc = float(frame - self.start_frame) / float(self.end_frame - self.start_frame) + self.values = tuple(start_value + truc * (end_value - start_value) + for (start_value, end_value) in zip(self.start_values, self.end_values))