# HG changeset patch # User Thibaut Girka # Date 1314213165 -7200 # Node ID af7914413b8909590d43c88ed8e1925c696b3983 # Parent 4fe37a620b226ea77dd61cf65bbf188e03a675fa Enable interpolators to use different formulas diff --git a/pytouhou/utils/interpolator.py b/pytouhou/utils/interpolator.py --- a/pytouhou/utils/interpolator.py +++ b/pytouhou/utils/interpolator.py @@ -14,17 +14,18 @@ class Interpolator(object): - def __init__(self, values=()): + def __init__(self, values=(), formula=None): self.values = tuple(values) self.start_values = tuple(values) self.end_values = tuple(values) self.start_frame = 0 self.end_frame = 0 self._frame = 0 + self._formula = formula or (lambda x: x) def __nonzero__(self): - return self._frame <= self.end_frame + return self._frame < self.end_frame def set_interpolation_start(self, frame, values): @@ -47,12 +48,12 @@ class Interpolator(object): def update(self, frame): self._frame = frame - if frame >= self.end_frame: + if frame >= self.end_frame - 1: 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) + coeff = self._formula(float(frame - self.start_frame) / float(self.end_frame - self.start_frame)) + self.values = tuple(start_value + coeff * (end_value - start_value) for (start_value, end_value) in zip(self.start_values, self.end_values))