Files
@ a38955ba6f40
Branch filter:
Location: light9/light9/Effects.py
a38955ba6f40
3.6 KiB
text/x-python
rdfdb port is now in the config
Ignore-this: 62a97aed9e0fe42604b8b59009b3d0e6
Ignore-this: 62a97aed9e0fe42604b8b59009b3d0e6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | from __future__ import division
import random as random_mod
import math
import logging, colorsys
import light9.Submaster as Submaster
from chase import chase as chase_logic
import showconfig
from rdflib import RDF
from light9 import Patch
from light9.namespaces import L9
log = logging.getLogger()
registered = []
def register(f):
registered.append(f)
return f
@register
def chase(t, ontime=0.5, offset=0.2, onval=1.0,
offval=0.0, names=None, combiner=max, random=False):
"""names is list of URIs. returns a submaster that chases through
the inputs"""
if random:
r = random_mod.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():
try:
dmx = Patch.dmx_from_uri(uri)
except KeyError:
log.info(("chase includes %r, which doesn't resolve to a dmx chan" %
uri))
continue
lev[dmx] = value
return Submaster.Submaster(name="chase" ,levels=lev)
@register
def hsv(h, s, v, light='all', centerScale=.5):
r,g,b = colorsys.hsv_to_rgb(h % 1.0, s, v)
lev = {}
if light in ['left', 'all']:
lev[73], lev[74], lev[75] = r,g,b
if light in ['right', 'all']:
lev[80], lev[81], lev[82] = r,g,b
if light in ['center', 'all']:
lev[88], lev[89], lev[90] = r*centerScale,g*centerScale,b*centerScale
return Submaster.Submaster(name='hsv', levels=lev)
@register
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 i, uri in enumerate(names):
if t >= (i + 1) * frac:
try:
dmx = Patch.dmx_from_uri(uri)
except KeyError:
log.info(("stack includes %r, which doesn't resolve to a dmx chan"%
uri))
continue
lev[dmx] = 1
else:
break
return Submaster.Submaster(name="stack", levels=lev)
@register
def smoove(x):
return -2 * (x ** 3) + 3 * (x ** 2)
def configExprGlobals():
graph = showconfig.getGraph()
ret = {}
for chaseUri in graph.subjects(RDF.type, L9['Chase']):
shortName = chaseUri.rsplit('/')[-1]
chans = graph.value(chaseUri, L9['channels'])
ret[shortName] = list(graph.items(chans))
print "%r is a chase" % shortName
for f in registered:
ret[f.__name__] = f
ret['nsin'] = lambda x: (math.sin(x * (2 * math.pi)) + 1) / 2
ret['ncos'] = lambda x: (math.cos(x * (2 * math.pi)) + 1) / 2
_smooth_random_items = [random_mod.random() for x in range(100)]
# suffix '2' to keep backcompat with the versions that magically knew time
def smooth_random2(t, speed=1):
"""1 = new stuff each second, <1 is slower, fade-ier"""
x = (t * speed) % len(_smooth_random_items)
x1 = int(x)
x2 = (int(x) + 1) % len(_smooth_random_items)
y1 = _smooth_random_items[x1]
y2 = _smooth_random_items[x2]
return y1 + (y2 - y1) * ((x - x1))
def notch_random2(t, speed=1):
"""1 = new stuff each second, <1 is slower, notch-ier"""
x = (t * speed) % len(_smooth_random_items)
x1 = int(x)
y1 = _smooth_random_items[x1]
return y1
ret['noise2'] = smooth_random2
ret['notch2'] = notch_random2
return ret
|