changeset 1443:dd3f72ac7214

effect eval support scaling of floats and Decimals Ignore-this: 1163a5558531dab5324718d30c25be2e
author drewp@bigasterisk.com
date Sat, 11 Jun 2016 21:14:55 +0000
parents 3e52568394ef
children 5bd2d036ae74
files light9/effect/effecteval.py
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/light9/effect/effecteval.py	Sat Jun 11 21:14:10 2016 +0000
+++ b/light9/effect/effecteval.py	Sat Jun 11 21:14:55 2016 +0000
@@ -2,6 +2,7 @@
 from rdflib import URIRef, Literal
 from light9.namespaces import L9, RDF
 from webcolors import rgb_to_hex, hex_to_rgb
+from decimal import Decimal
 import math
 
 def literalColor(rnorm, gnorm, bnorm):
@@ -10,11 +11,18 @@
 def scale(value, strength):
     if isinstance(value, Literal):
         value = value.toPython()
+
+    if isinstance(value, Decimal):
+        value = float(value)
+        
     if isinstance(value, basestring):
         if value[0] == '#':
             r,g,b = hex_to_rgb(value)
             return rgb_to_hex([r * strength, g * strength, b * strength])
-    raise NotImplementedError(repr(value))
+    elif isinstance(value, (int, float)):
+        return value * strength
+    else:
+        raise NotImplementedError(repr(value))
     
 class EffectEval(object):
     """