changeset 579:ff36ce3038be

Effects: chase can now randomize with random kw, add stack (untested!) Ignore-this: 977a062ab00c40b629b568f72c70562f
author David McClosky <dmcc@bigasterisk.com>
date Sat, 19 Jun 2010 23:40:33 +0000
parents a4b1e51d8169
children 0b8222617b75
files light9/Effects.py
diffstat 1 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/light9/Effects.py	Sat Jun 19 23:40:24 2010 +0000
+++ b/light9/Effects.py	Sat Jun 19 23:40:33 2010 +0000
@@ -1,5 +1,5 @@
 from __future__ import division
-import random
+from random import Random
 import light9.Submaster as Submaster
 from chase import chase as chase_logic
 import showconfig
@@ -8,10 +8,14 @@
 from light9.namespaces import L9
 
 def chase(t, ontime=0.5, offset=0.2, onval=1.0, 
-          offval=0.0, names=None, combiner=max):
+          offval=0.0, names=None, combiner=max, random=False):
     """names is list of URIs. returns a submaster that chases through
     the inputs"""
-    sub_vals = {}
+    if random:
+        r = Random(random)
+        names = names[:]
+        r.shuffle(names)
+
     chase_vals = chase_logic(t, ontime, offset, onval, offval, names, combiner)
     lev = {}
     for uri, value in chase_vals.items():
@@ -26,6 +30,28 @@
     ret = Submaster.Submaster(leveldict=lev, temporary=True)
     return ret
 
+def stack(t, names=None):
+    """names is list of URIs. returns a submaster that stacks the the inputs"""
+    frac = 1.0 / (len(names) + 1)
+    threshold = frac
+
+    lev = {}
+    for uri in names:
+        try:
+            dmx = Patch.dmx_from_uri(uri)
+        except KeyError:
+            print ("chase includes %r, which doesn't resolve to a dmx chan" %
+                   uri)
+            continue
+        lev[dmx] = 1
+
+        threshold += frac
+        if threshold > t:
+            break
+
+    ret = Submaster.Submaster(leveldict=lev, temporary=True)
+    return ret
+
 def configExprGlobals():
     graph = showconfig.getGraph()
     ret = {}