changeset 291:6c3b487e7bbc

Basic chase logic (does not do bounces correctly) Plus a tiny bit of testing code
author David McClosky <dmcc@bigasterisk.com>
date Sat, 18 Jun 2005 07:35:29 +0000
parents 50ba9ec2b17e
children e841bea500c3
files light9/chase.py
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/chase.py	Sat Jun 18 07:35:29 2005 +0000
@@ -0,0 +1,35 @@
+from __future__ import division
+
+def chase(t, ontime=0.5, offtime=0.5, offset=0.2, onval=1.0, 
+          offval=0.0, names=None, combiner=max):
+    names = names or []
+    period = ontime + offtime
+    outputs = {}
+    for index, name in enumerate(names):
+        # normalize our time
+        local_offset = offset * index
+        local_t = t - local_offset
+        local_t %= period
+
+        # see if we're still in the on part
+        if local_t <= ontime:
+            value = onval
+        else:
+            value = offval
+
+        # it could be in there twice (in a bounce like (1, 2, 3, 2)
+        if name in outputs:
+            outputs[name] = max(value, outputs[name])
+        else:
+            outputs[name] = value
+    return outputs
+
+if __name__ == "__main__":
+    # a little testing
+    for x in range(80):
+        x /= 20.0
+        output = chase(x, onval='x', offval=' ', ontime=0.3, offtime=0.6,
+                       names=('a', 'b', 'c', 'd'))
+        output = output.items()
+        output.sort()
+        print "%.2f\t%s" % (x, ' '.join([str(x) for x in output]))