From fc08b8c36eab9feba98ddf1bd284b3246f9c4f5e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 17 Mar 2014 21:50:39 +0100 Subject: implement _standardise, _manipulate, _linearise and _sigmoid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/lisp-esque | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'examples') diff --git a/examples/lisp-esque b/examples/lisp-esque index 61e1586..b26631f 100644 --- a/examples/lisp-esque +++ b/examples/lisp-esque @@ -443,7 +443,7 @@ class Negative: def __init__(self): self.monitors = [(False, False, False, False, False, False)] def __call__(self, monitor, alpha): - negative(*(self.monitors[monitor][3 if alpha == 0 else 0:][:3])) + negative(*(self.monitors[monitor % len(self.monitors)][3 if alpha == 0 else 0:][:3])) def _negative(mods, args): ''' @@ -487,7 +487,7 @@ class RGBInvert: def __init__(self): self.monitors = [(False, False, False, False, False, False)] def __call__(self, monitor, alpha): - rgb_invert(*(self.monitors[monitor][3 if alpha == 0 else 0:][:3])) + rgb_invert(*(self.monitors[monitor % len(self.monitors)][3 if alpha == 0 else 0:][:3])) class CIEInvert: ''' @@ -496,7 +496,7 @@ class CIEInvert: def __init__(self): self.monitors = [(False, False, False, False, False, False)] def __call__(self, monitor, alpha): - cie_invert(*(self.monitors[monitor][3 if alpha == 0 else 0:][:3])) + cie_invert(*(self.monitors[monitor % len(self.monitors)][3 if alpha == 0 else 0:][:3])) def _invert(mods, args): ''' @@ -662,8 +662,15 @@ def _sigmoid(mods, args): |list<[str, str, str]>> optionally with individual colour curve control; 'nil' for nothing ''' + red = 'red' in mods + green = 'green' in mods + blue = 'blue' in mods args = evaluate_tree(args, True) - pass + args = [[arg, arg, arg] if isinstance(arg, str) else arg for arg in args] + args = [[None if a == 'nil' else float(a) for a in arg] for arg in args] + if red or green or blue: + args = [[arg[0] if red else None, arg[1] if green else None, arg[2] if blue else None] for arg in args] + adjustments.append(lambda monitor : sigmoid(*(args[monitor % len(args)]))) def _limits(mods, args): @@ -680,7 +687,7 @@ def _limits(mods, args): |list> optionally at each time point (outer) ''' args = evaluate_tree(args, True) - pass + pass # TODO (limits) def _linearise(mods, args): @@ -692,8 +699,15 @@ def _linearise(mods, args): monitor (or all of them) on whether to convert the curve, 'yes' implied for all monitors if empty ''' + red = 'red' in mods + green = 'green' in mods + blue = 'blue' in mods args = evaluate_tree(args, True) - pass + args = [[arg, arg, arg] if isinstance(arg, str) else arg for arg in args] + args = [[a == 'yes' for a in arg] for arg in args] + if red or green or blue: + args = [[arg[0] and red, arg[1] and green, arg[2] and blue] for arg in args] + adjustments.append(lambda monitor : linearise(*(args[monitor % len(args)]))) def _icc(mods, args): @@ -706,7 +720,7 @@ def _icc(mods, args): and optionally (inner) for each monitor. ''' args = evaluate_tree(args, False) - pass + pass # TODO (icc) def _manipulate(mods, args): @@ -719,8 +733,15 @@ def _manipulate(mods, args): @param args:list<[str, str, str]|str> Function for each monitor (for all if just one specified), and optionally one per colour curve (red, green and blue) ''' - args = evaluate_tree(args, True) - pass + red = 'red' in mods + green = 'green' in mods + blue = 'blue' in mods + args = evaluate_tree(args, False) + args = [[arg, arg, arg] if isinstance(arg, str) else arg for arg in args] + args = [[None if a == 'nil' else eval(a) for a in arg] for arg in args] + if red or green or blue: + args = [[arg[0] if red else None, arg[1] if green else None, arg[2] if blue else None] for arg in args] + adjustments.append(lambda monitor : manipulate(*(args[monitor % len(args)]))) def _standardise(mods, args): @@ -732,8 +753,15 @@ def _standardise(mods, args): monitor (or all of them) on whether to convert the curve, 'yes' implied for all monitors if empty ''' + red = 'red' in mods + green = 'green' in mods + blue = 'blue' in mods args = evaluate_tree(args, True) - pass + args = [[arg, arg, arg] if isinstance(arg, str) else arg for arg in args] + args = [[a == 'yes' for a in arg] for arg in args] + if red or green or blue: + args = [[arg[0] and red, arg[1] and green, arg[2] and blue] for arg in args] + adjustments.append(lambda monitor : standardise(*(args[monitor % len(args)]))) # Map function names to functions -- cgit v1.2.3-70-g09d2