changeset 606:3ed6a6b39f39

rewrite stack() Ignore-this: f4540894080f2714fb411c6385d2975f
author drewp@bigasterisk.com
date Sun, 20 Jun 2010 23:15:57 +0000
parents 40724a613b40
children e3c89cd854f5
files light9/Effects.py
diffstat 1 files changed, 18 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/light9/Effects.py	Sun Jun 20 23:15:45 2010 +0000
+++ b/light9/Effects.py	Sun Jun 20 23:15:57 2010 +0000
@@ -29,25 +29,27 @@
 
     return Submaster.Submaster(leveldict=lev, temporary=True)
 
-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
+def stack(t, names=None, fade=0):
+    """names is list of URIs. returns a submaster that stacks the the inputs
+
+    fade=0 makes steps, fade=1 means each one gets its full fraction
+    of the time to fade in. Fades never...
+    """
+    frac = 1.0 / len(names)
 
     lev = {}
-    for uri in names:
-        try:
-            dmx = Patch.dmx_from_uri(uri)
-        except KeyError:
-            print ("stack includes %r, which doesn't resolve to a dmx chan" %
-                   uri)
-            continue
-        lev[dmx] = 1
-
-        threshold += frac
-        if threshold > t:
+    for i, uri in enumerate(names):
+        if t >= (i + 1) * frac:
+            try:
+                dmx = Patch.dmx_from_uri(uri)
+            except KeyError:
+                print ("stack includes %r, which doesn't resolve to a dmx chan"%
+                       uri)
+                continue
+            lev[dmx] = 1
+        else:
             break
-
+    
     return Submaster.Submaster(leveldict=lev, temporary=True)
 
 def configExprGlobals():