Skip to content
Browse files

Integrate curves into MMLX

  • Loading branch information...
1 parent e03a9e4 commit c4405eccf9f8dde9188f49f00828b6c4260139a4 @ccampbell committed
Showing with 17 additions and 41 deletions.
  1. +17 −41 mmlxlib/magicmacro.py
View
58 mmlxlib/magicmacro.py
@@ -15,6 +15,7 @@
# limitations under the License.
import re
import math
+from curve import Curve
class MagicMacro(object):
@@ -31,8 +32,11 @@ def repeat(self, count):
def step(self, size):
self.step_size = float(size)
- def curve(self, type="+"):
- self.curve_type = type
+ def curve(self, type=None):
+ if not type:
+ type = "easeInQuad"
+
+ self.curve_type = type.replace('\'', '').replace('"', '')
def processRepeats(self, macro):
return ((' ' + macro) * int(self.repeat_count)).replace(' ', ' ')
@@ -54,44 +58,16 @@ def easeInQuad(self, t, b, c, d):
return c * t * t + b
def processCurve(self, macro):
- return macro
- # begin = 0
- # finish = 15
- # change = finish - begin
- # duration = 15
- # time = 0
-
- # while time <= duration:
- # pos = self.easeInQuad(time, begin, change, duration)
- # print math.floor(pos)
-
- # time += 1
- # # print time
-
- # return macro
- # first = int(macro.split(' ')[0])
- # last = int(macro.split(' ').pop())
- # total_steps = abs(last - first + 1)
-
- # # xs = [1, int(total_steps / 2), total_steps]
- # # print self.curve_type
- # # cushion = (last - first) / 15
- # # ys = [first, last if self.curve_type == '-' else first + cushion, last]
- # # print xs, ys
- # xs = [1, 8, 13]
- # ys = [3, 3, 15]
-
- # equation = numpy.poly1d(numpy.polyfit(xs, ys, deg=2))
-
- # step_size = self.step_size or 1
- # values = []
- # i = 1
- # while i <= total_steps:
- # print '(' + str(i) + ', ' + str(int(round(equation(i)))) + ')'
- # values.append(str(int(round(equation(i)))))
- # i += step_size
-
- # return " ".join(values)
+ begin = float(macro.split(' ')[0])
+ end = float(macro.split(' ').pop())
+ change = float(end - begin)
+ duration = change * (1 / self.step_size) if self.step_size is not None else change
+
+ curve = Curve(begin, end, duration)
+ if hasattr(curve, self.curve_type):
+ return curve.render(self.curve_type)
+
+ raise Exception('curve doex not exist with type: ' + self.curve_type)
def getMagicSteps(self, first, last, rate):
values = []
@@ -137,7 +113,7 @@ def __str__(self):
if self.curve_type is not None:
return self.processCurve(macro)
- if self.step_size is not None:
+ if self.curve_type is None and self.step_size is not None:
macro = self.processSteps(macro)
if self.repeat_count is not None:

0 comments on commit c4405ec

Please sign in to comment.
Something went wrong with that request. Please try again.