Changeset - dd3f72ac7214
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 9 years ago 2016-06-11 21:14:55
drewp@bigasterisk.com
effect eval support scaling of floats and Decimals
Ignore-this: 1163a5558531dab5324718d30c25be2e
1 file changed with 9 insertions and 1 deletions:
0 comments (0 inline, 0 general)
light9/effect/effecteval.py
Show inline comments
 
@@ -2,6 +2,7 @@ from __future__ import division
 
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 literalColor(rnorm, gnorm, bnorm):
 
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):
 
    """
0 comments (0 inline, 0 general)