From ee57ac012330e4f7de66c53555ea279e8149df3c Mon Sep 17 00:00:00 2001 From: HomeWorld Date: Sun, 15 May 2011 18:10:27 +0300 Subject: [PATCH] Moved animation effects to gui.utils.animEffects.py . Modified pygauge --- gui/pygauge.py | 84 +--------------------------------------- gui/utils/animEffects.py | 83 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 82 deletions(-) create mode 100644 gui/utils/animEffects.py diff --git a/gui/pygauge.py b/gui/pygauge.py index 660e10665..356c6f6f2 100644 --- a/gui/pygauge.py +++ b/gui/pygauge.py @@ -17,6 +17,7 @@ import math from gui.utils import colorUtils import gui.utils.drawUtils as drawUtils +import gui.utils.animEffects as animEffects class PyGauge(wx.PyWindow): """ @@ -372,87 +373,6 @@ class PyGauge(wx.PyWindow): dc.SetTextForeground(wx.Colour(255,255,255)) dc.DrawLabel(formatStr.format(value), rect, wx.ALIGN_CENTER) - def OUT_CIRC (self, t, b, c, d): - t=float(t) - b=float(b) - c=float(c) - d=float(d) - t = t/d -1 - return c * math.sqrt(1 - t*t) + b; - - def OUT_QUART(self, t, b, c, d): - t=float(t) - b=float(b) - c=float(c) - d=float(d) - t = t/d -1 - return -c * ((t)*t*t*t - 1) + b; - - def INOUT_CIRC(self, t, b, c, d): - t=float(t) - b=float(b) - c=float(c) - d=float(d) - t1 = t / (d / 2) - - if ((t / (d/2)) < 1): - return -c/2 * (math.sqrt(1 - (t/(d/2))**2) - 1) + b - return c/2 * (math.sqrt(1 - (t1-2)**2) + 1) + b; - - def IN_CUBIC (self, t, b, c, d): - t=float(t) - b=float(b) - c=float(c) - d=float(d) - t = t/d - return c*t*t*t + b - - def OUT_QUAD (self, t, b, c, d): - t=float(t) - b=float(b) - c=float(c) - d=float(d) - - t/=d - - return -c *(t)*(t-2) + b - - def OUT_BOUNCE (self, t, b, c, d): - t=float(t) - b=float(b) - c=float(c) - d=float(d) - - t/=d - - if ((t) < (1/2.75)): - return c*(7.5625*t*t) + b - else: - if (t < (2/2.75)): - t-=(1.5/2.75) - return c*(7.5625*t*t + .75) + b - else: - if (t < (2.5/2.75)): - t-=(2.25/2.75) - return c*(7.5625*(t)*t + .9375) + b - else: - t-=(2.625/2.75) - return c*(7.5625*(t)*t + .984375) + b - - def INOUT_EXP(self, t, b, c, d): - t=float(t) - b=float(b) - c=float(c) - d=float(d) - t1 = t / (d/2) - if t==0: - return b - if t==d: - return b+c - if (t1) < 1: - return c/2 * math.pow(2, 10 * (t1 - 1)) + b - c * 0.0005 - return c/2 * 1.0005 * (-math.pow(2, -10 * (t1-1)) + 2) + b - def OnTimer(self,event): """ @@ -472,7 +392,7 @@ class PyGauge(wx.PyWindow): start = 0 end = oldValue - value self._animDirection = direction - step=self.OUT_QUAD(self._animStep, start, end, self._animDuration) + step=animEffects.OUT_QUAD(self._animStep, start, end, self._animDuration) self._animStep += self._period diff --git a/gui/utils/animEffects.py b/gui/utils/animEffects.py new file mode 100644 index 000000000..519fe60c4 --- /dev/null +++ b/gui/utils/animEffects.py @@ -0,0 +1,83 @@ + +import math + +def OUT_CIRC (t, b, c, d): + t=float(t) + b=float(b) + c=float(c) + d=float(d) + t = t/d -1 + return c * math.sqrt(1 - t*t) + b; + +def OUT_QUART(t, b, c, d): + t=float(t) + b=float(b) + c=float(c) + d=float(d) + t = t/d -1 + return -c * ((t)*t*t*t - 1) + b; + +def INOUT_CIRC(t, b, c, d): + t=float(t) + b=float(b) + c=float(c) + d=float(d) + t1 = t / (d / 2) + + if ((t / (d/2)) < 1): + return -c/2 * (math.sqrt(1 - (t/(d/2))**2) - 1) + b + return c/2 * (math.sqrt(1 - (t1-2)**2) + 1) + b; + +def IN_CUBIC (t, b, c, d): + t=float(t) + b=float(b) + c=float(c) + d=float(d) + t = t/d + return c*t*t*t + b + +def OUT_QUAD (t, b, c, d): + t=float(t) + b=float(b) + c=float(c) + d=float(d) + + t/=d + + return -c *(t)*(t-2) + b + +def OUT_BOUNCE (t, b, c, d): + t=float(t) + b=float(b) + c=float(c) + d=float(d) + + t/=d + + if ((t) < (1/2.75)): + return c*(7.5625*t*t) + b + else: + if (t < (2/2.75)): + t-=(1.5/2.75) + return c*(7.5625*t*t + .75) + b + else: + if (t < (2.5/2.75)): + t-=(2.25/2.75) + return c*(7.5625*(t)*t + .9375) + b + else: + t-=(2.625/2.75) + return c*(7.5625*(t)*t + .984375) + b + +def INOUT_EXP(t, b, c, d): + t=float(t) + b=float(b) + c=float(c) + d=float(d) + t1 = t / (d/2) + if t==0: + return b + if t==d: + return b+c + if (t1) < 1: + return c/2 * math.pow(2, 10 * (t1 - 1)) + b - c * 0.0005 + return c/2 * 1.0005 * (-math.pow(2, -10 * (t1-1)) + 2) + b