# HG changeset patch # User David McClosky # Date 2005-06-18 16:59:04 # Node ID 1c590824dd14fe735b573d3e45bbdcda9948969f # Parent e841bea500c3ea520c6c3b198277675cca847a64 chase logic is (mostly) fixed, integrate with curvecalc Also add some quick names for chases diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -15,12 +15,19 @@ from twisted.web.xmlrpc import Proxy import run_local from light9 import Submaster, dmxclient, networking, showconfig -from light9.TLUtility import make_attributes_from_args +from light9.TLUtility import make_attributes_from_args, dict_subset from light9.zoomcontrol import Zoomcontrol from light9.curve import Curve, Curveview, Curveset, Curvesetview from light9.wavelength import wavelength from light9.uihelpers import toplevelat +import light9.Effects +fx_dict = light9.Effects.__dict__ +all_fx = fx_dict['__all__'] +expr_helpers = dict_subset(fx_dict, all_fx) +del fx_dict +del all_fx + class Music: def __init__(self): self.player=None # xmlrpc Proxy to player @@ -65,6 +72,9 @@ class Subexpr: glo = self.curveset.globalsdict() glo['t'] = t + # add in functions from Effects + glo.update(expr_helpers) + glo['nsin'] = lambda x: (math.sin(x * (2 * math.pi)) + 1) / 2 glo['ncos'] = lambda x: (math.cos(x * (2 * math.pi)) + 1) / 2 glo['within'] = lambda a, b: a < t < b diff --git a/light9/chase.py b/light9/chase.py --- a/light9/chase.py +++ b/light9/chase.py @@ -1,13 +1,15 @@ from __future__ import division -def chase(t, ontime=0.5, offtime=0.5, offset=0.2, onval=1.0, +def chase(t, ontime=0.5, offset=0.2, onval=1.0, offval=0.0, names=None, combiner=max): names = names or [] - period = ontime + offtime + # maybe this is better: + # period = ontime + ((offset + ontime) * (len(names) - 1)) + period = (offset + ontime) * len(names) outputs = {} for index, name in enumerate(names): # normalize our time - local_offset = offset * index + local_offset = (offset + ontime) * index local_t = t - local_offset local_t %= period @@ -19,7 +21,7 @@ def chase(t, ontime=0.5, offtime=0.5, of # it could be in there twice (in a bounce like (1, 2, 3, 2) if name in outputs: - outputs[name] = max(value, outputs[name]) + outputs[name] = combiner(value, outputs[name]) else: outputs[name] = value return outputs @@ -28,7 +30,7 @@ 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, + output = chase(x, onval='x', offval=' ', ontime=0.1, offset=0.2, names=('a', 'b', 'c', 'd')) output = output.items() output.sort()