annotate light9/Effects.py @ 1898:d3091e6dd1a0

more initial data for 2019 show Ignore-this: 1bf5c652531d8653ae74528414b772ef
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 30 May 2019 17:14:11 +0000
parents 1aa91a31c0e2
children ccdfdc8183ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
1 import random as random_mod
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
2 import math
989
d91015a384fb new hsv effect for controlling some leds. channels not configurable yet
drewp@bigasterisk.com
parents: 914
diff changeset
3 import logging, colorsys
324
f913fc297b2d add back_colors and zips light lists for chases
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
4 import light9.Submaster as Submaster
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
5 from .chase import chase as chase_logic
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
6 from . import showconfig
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
7 from rdflib import RDF
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
8 from light9 import Patch
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
9 from light9.namespaces import L9
790
690c837f8842 logging
drewp@bigasterisk.com
parents: 606
diff changeset
10 log = logging.getLogger()
324
f913fc297b2d add back_colors and zips light lists for chases
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
11
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
12 registered = []
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
13
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
14
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
15 def register(f):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
16 registered.append(f)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
17 return f
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
18
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
19
1124
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
20 @register
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
21 class Strip(object):
1115
818275850003 effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
22 """list of r,g,b tuples for sending to an LED strip"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
23 which = 'L' # LR means both. W is the wide one
1115
818275850003 effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
24 pixels = []
1394
0bfaeaa40cfe debug effects
drewp@bigasterisk.com
parents: 1254
diff changeset
25
0bfaeaa40cfe debug effects
drewp@bigasterisk.com
parents: 1254
diff changeset
26 def __repr__(self):
1395
b6ba0e7d126b workaround for missing effects in songs
drewp@bigasterisk.com
parents: 1394
diff changeset
27 return '<Strip which=%r px0=%r>' % (self.which, self.pixels[0])
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
28
1124
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
29 @classmethod
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
30 def solid(cls, which='L', color=(1, 1, 1), hsv=None):
1198
c98a239e0d0b new effects
drewp@bigasterisk.com
parents: 1152
diff changeset
31 """hsv overrides color"""
c98a239e0d0b new effects
drewp@bigasterisk.com
parents: 1152
diff changeset
32 if hsv is not None:
c98a239e0d0b new effects
drewp@bigasterisk.com
parents: 1152
diff changeset
33 color = colorsys.hsv_to_rgb(hsv[0] % 1.0, hsv[1], hsv[2])
1124
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
34 x = cls()
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
35 x.which = which
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
36 x.pixels = [tuple(color)] * 50
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
37 return x
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
38
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
39 def __mul__(self, f):
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
40 if not isinstance(f, (int, float)):
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
41 raise TypeError
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
42
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
43 s = Strip()
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
44 s.which = self.which
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
45 s.pixels = [(r * f, g * f, b * f) for r, g, b in self.pixels]
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
46 return s
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
47
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
48 __rmul__ = __mul__
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1124
diff changeset
49
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
50
1124
4eb7dc40797f just called Strip now
Drew Perttula <drewp@bigasterisk.com>
parents: 1121
diff changeset
51 @register
1115
818275850003 effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
52 class Blacklight(float):
818275850003 effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
53 """a level for the blacklight PWM output"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
54
1137
05f272019697 Blacklight can multiply and keep its type
drewp@bigasterisk.com
parents: 1136
diff changeset
55 def __mul__(self, f):
1138
a073565e826e ..without recursion
drewp@bigasterisk.com
parents: 1137
diff changeset
56 return Blacklight(float(self) * f)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
57
1137
05f272019697 Blacklight can multiply and keep its type
drewp@bigasterisk.com
parents: 1136
diff changeset
58 __rmul__ = __mul__
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
59
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
60
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
61 @register
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
62 def chase(t,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
63 ontime=0.5,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
64 offset=0.2,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
65 onval=1.0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
66 offval=0.0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
67 names=None,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
68 combiner=max,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
69 random=False):
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
70 """names is list of URIs. returns a submaster that chases through
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
71 the inputs"""
579
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
72 if random:
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
73 r = random_mod.Random(random)
579
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
74 names = names[:]
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
75 r.shuffle(names)
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
76
324
f913fc297b2d add back_colors and zips light lists for chases
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
77 chase_vals = chase_logic(t, ontime, offset, onval, offval, names, combiner)
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
78 lev = {}
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
79 for uri, value in list(chase_vals.items()):
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
80 try:
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
81 dmx = Patch.dmx_from_uri(uri)
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
82 except KeyError:
790
690c837f8842 logging
drewp@bigasterisk.com
parents: 606
diff changeset
83 log.info(("chase includes %r, which doesn't resolve to a dmx chan" %
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
84 uri))
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
85 continue
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
86 lev[dmx] = value
324
f913fc297b2d add back_colors and zips light lists for chases
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
87
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
88 return Submaster.Submaster(name="chase", levels=lev)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
89
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
90
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
91 @register
989
d91015a384fb new hsv effect for controlling some leds. channels not configurable yet
drewp@bigasterisk.com
parents: 914
diff changeset
92 def hsv(h, s, v, light='all', centerScale=.5):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
93 r, g, b = colorsys.hsv_to_rgb(h % 1.0, s, v)
989
d91015a384fb new hsv effect for controlling some leds. channels not configurable yet
drewp@bigasterisk.com
parents: 914
diff changeset
94 lev = {}
d91015a384fb new hsv effect for controlling some leds. channels not configurable yet
drewp@bigasterisk.com
parents: 914
diff changeset
95 if light in ['left', 'all']:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
96 lev[73], lev[74], lev[75] = r, g, b
989
d91015a384fb new hsv effect for controlling some leds. channels not configurable yet
drewp@bigasterisk.com
parents: 914
diff changeset
97 if light in ['right', 'all']:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
98 lev[80], lev[81], lev[82] = r, g, b
989
d91015a384fb new hsv effect for controlling some leds. channels not configurable yet
drewp@bigasterisk.com
parents: 914
diff changeset
99 if light in ['center', 'all']:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
100 lev[88], lev[89], lev[
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
101 90] = r * centerScale, g * centerScale, b * centerScale
989
d91015a384fb new hsv effect for controlling some leds. channels not configurable yet
drewp@bigasterisk.com
parents: 914
diff changeset
102 return Submaster.Submaster(name='hsv', levels=lev)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
103
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
104
1115
818275850003 effecteval screens for only the kinds of outputs that it can send, so i can run a second instance just for LEDs
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
105 @register
606
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
106 def stack(t, names=None, fade=0):
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
107 """names is list of URIs. returns a submaster that stacks the the inputs
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
108
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
109 fade=0 makes steps, fade=1 means each one gets its full fraction
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
110 of the time to fade in. Fades never...
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
111 """
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
112 frac = 1.0 / len(names)
579
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
113
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
114 lev = {}
606
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
115 for i, uri in enumerate(names):
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
116 if t >= (i + 1) * frac:
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
117 try:
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
118 dmx = Patch.dmx_from_uri(uri)
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
119 except KeyError:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
120 log.info(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
121 ("stack includes %r, which doesn't resolve to a dmx chan" %
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
122 uri))
606
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
123 continue
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
124 lev[dmx] = 1
3ed6a6b39f39 rewrite stack()
drewp@bigasterisk.com
parents: 594
diff changeset
125 else:
579
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
126 break
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
127
914
092c00f6ba25 fixes for Submaster init method
drewp@bigasterisk.com
parents: 790
diff changeset
128 return Submaster.Submaster(name="stack", levels=lev)
579
ff36ce3038be Effects: chase can now randomize with random kw, add stack (untested!)
David McClosky <dmcc@bigasterisk.com>
parents: 447
diff changeset
129
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
130
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
131 @register
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
132 def smoove(x):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
133 return -2 * (x**3) + 3 * (x**2)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
134
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
135
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
136 def configExprGlobals():
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
137 graph = showconfig.getGraph()
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
138 ret = {}
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
139
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
140 for chaseUri in graph.subjects(RDF.type, L9['Chase']):
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
141 shortName = chaseUri.rsplit('/')[-1]
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
142 chans = graph.value(chaseUri, L9['channels'])
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
143 ret[shortName] = list(graph.items(chans))
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
144 print("%r is a chase" % shortName)
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
145
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
146 for f in registered:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
147 ret[f.__name__] = f
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
148
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
149 ret['nsin'] = lambda x: (math.sin(x * (2 * math.pi)) + 1) / 2
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
150 ret['ncos'] = lambda x: (math.cos(x * (2 * math.pi)) + 1) / 2
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
151
1198
c98a239e0d0b new effects
drewp@bigasterisk.com
parents: 1152
diff changeset
152 def nsquare(t, on=.5):
c98a239e0d0b new effects
drewp@bigasterisk.com
parents: 1152
diff changeset
153 return (t % 1.0) < on
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1395
diff changeset
154
1198
c98a239e0d0b new effects
drewp@bigasterisk.com
parents: 1152
diff changeset
155 ret['nsquare'] = nsquare
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
156
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
157 _smooth_random_items = [random_mod.random() for x in range(100)]
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
158
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
159 # suffix '2' to keep backcompat with the versions that magically knew time
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
160 def smooth_random2(t, speed=1):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
161 """1 = new stuff each second, <1 is slower, fade-ier"""
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
162 x = (t * speed) % len(_smooth_random_items)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
163 x1 = int(x)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
164 x2 = (int(x) + 1) % len(_smooth_random_items)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
165 y1 = _smooth_random_items[x1]
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
166 y2 = _smooth_random_items[x2]
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
167 return y1 + (y2 - y1) * ((x - x1))
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
168
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
169 def notch_random2(t, speed=1):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
170 """1 = new stuff each second, <1 is slower, notch-ier"""
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
171 x = (t * speed) % len(_smooth_random_items)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
172 x1 = int(x)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
173 y1 = _smooth_random_items[x1]
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
174 return y1
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
175
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
176 ret['noise2'] = smooth_random2
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
177 ret['notch2'] = notch_random2
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 989
diff changeset
178
399
40b6a06bd090 rework Effects.py to fix chase(). now uses chase lists from config.n3
Drew Perttula <drewp@bigasterisk.com>
parents: 324
diff changeset
179 return ret