Changeset - 1c590824dd14
[Not reviewed]
default
0 2 0
David McClosky - 20 years ago 2005-06-18 16:59:04
dmcc@bigasterisk.com
chase logic is (mostly) fixed, integrate with curvecalc
Also add some quick names for chases
2 files changed with 18 insertions and 6 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -6,30 +6,37 @@ todo: curveview should preserve more obj
 
"""
 
from __future__ import division
 
import xmlrpclib,time,socket,sys,textwrap,math,glob,random,os,optparse
 
from bisect import bisect_left,bisect,bisect_right
 
import Tkinter as tk
 
from dispatch import dispatcher
 
from twisted.internet import reactor,tksupport
 
import twisted
 
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
 
        self.recenttime=0
 

	
 
        dispatcher.connect(self.seekplay_or_pause,"music seek")
 

	
 
    def seekplay_or_pause(self,t):
 
        self.music.seekplay_or_pause(t)
 
        
 
    def current_time(self):
 
        """return deferred which gets called with the current time"""
 
@@ -56,24 +63,27 @@ class Subexpr:
 
    def __init__(self,curveset,expr=""):
 
        self.curveset = curveset
 
        self.lasteval = None
 
        self.expr=expr
 
        self._smooth_random_items = [random.random() for x in range(100)]
 
    def eval(self,t):
 
        if self.expr=="":
 
            dispatcher.send("expr_error",sender=self,exc="no expr, using 0")
 
            return 0
 
        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
 
        glo['bef'] = lambda x: t < x
 
        glo['aft'] = lambda x: x < t
 
        glo['smoove'] = lambda x: -2 * (x ** 3) + 3 * (x ** 2)
 

	
 
        def smooth_random(speed=1):
 
            """1 = new stuff each second, <1 is slower, fade-ier"""
 
            x = (t * speed) % len(self._smooth_random_items)
 
            x1 = int(x)
 
            x2 = (int(x) + 1) % len(self._smooth_random_items)
light9/chase.py
Show inline comments
 
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
 

	
 
        # 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])
 
            outputs[name] = combiner(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,
 
        output = chase(x, onval='x', offval=' ', ontime=0.1, offset=0.2,
 
                       names=('a', 'b', 'c', 'd'))
 
        output = output.items()
 
        output.sort()
 
        print "%.2f\t%s" % (x, ' '.join([str(x) for x in output]))
0 comments (0 inline, 0 general)