Skip to content

Commit 99974fa

Browse files
committed
Dec 26 daily effect, xled_picture, and updates
1 parent df40f92 commit 99974fa

11 files changed

+244
-80
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.1.26'
1+
__version__ = '0.1.27'
22

33
_classifiers = [
44
'Development Status :: 4 - Beta',

xled_plus/highcontrol.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,16 @@ def fetch_layout(self, aspect=False):
651651
}
652652
if dim == 3:
653653
crad = 0.0
654+
hsrad = 0.0
654655
for p in self.layout:
655656
r2 = (p[0] - cent[0]) ** 2 + (p[2] - cent[2]) ** 2
656657
if r2 > crad:
657658
crad = r2
659+
r2 += (p[1] - bounds[1][0]) ** 2
660+
if r2 > hsrad:
661+
hsrad = r2
658662
self.layout_bounds["cylradius"] = crad ** 0.5
663+
self.layout_bounds["halfsradius"] = hsrad ** 0.5
659664

660665
def layout_transform(self, pos, style):
661666
# style == 'square', 'rect', 'centered', 'cylinder', 'sphere'
@@ -680,21 +685,31 @@ def layout_transform(self, pos, style):
680685
# xz-radius max 1, angle in [-180,180], y in [0, 1]
681686
crad = self.layout_bounds["cylradius"]
682687
ybounds = self.layout_bounds["bounds"][1]
683-
p = ((v - c) / crad for v, c in zip(pos, self.layout_bounds["center"]))
688+
p = tuple((v - c) / crad for v, c in zip(pos, self.layout_bounds["center"]))
684689
return (
685690
m.sqrt(p[0] ** 2 + p[2] ** 2),
686-
m.atan2(p[2], p[0]) * 180.0 / m.pi,
687-
(p[1] * crad - ybounds[0]) / (ybounds[1] - ybounds[0]),
691+
m.atan2(p[0], p[2]) * 180.0 / m.pi,
692+
(pos[1] - ybounds[0]) / (ybounds[1] - ybounds[0]),
688693
)
689694
elif style == "sphere" and self.layout_bounds["dim"] == 3:
690695
# radius max 1, longitude [-180,180], latitude [-90,90]
691696
rad = self.layout_bounds["radius"]
692-
p = ((v - c) / rad for v, c in zip(pos, self.layout_bounds["center"]))
697+
p = tuple((v - c) / rad for v, c in zip(pos, self.layout_bounds["center"]))
693698
return (
694699
m.sqrt(p[0] ** 2 + p[1] ** 2 + p[2] ** 2),
695-
m.atan2(p[2], p[0]) * 180.0 / m.pi,
700+
m.atan2(p[0], p[2]) * 180.0 / m.pi,
696701
m.atan2(p[1], m.sqrt(p[0] ** 2 + p[2] ** 2)) * 180.0 / m.pi,
697702
)
703+
elif style == "halfsphere" and self.layout_bounds["dim"] == 3:
704+
# radius max 1, longitude [-180,180], polar angle [0,90]
705+
rad = self.layout_bounds["halfsradius"]
706+
cent = (self.layout_bounds["center"][0], self.layout_bounds["bounds"][1][0], self.layout_bounds["center"][2])
707+
p = tuple((v - c) / rad for v, c in zip(pos, cent))
708+
return (
709+
m.sqrt(p[0] ** 2 + p[1] ** 2 + p[2] ** 2),
710+
m.atan2(p[0], p[2]) * 180.0 / m.pi,
711+
m.atan2(m.sqrt(p[0] ** 2 + p[2] ** 2), p[1]) * 180.0 / m.pi,
712+
)
698713
else:
699714
return pos
700715

xled_plus/samples/day19.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, ctr):
2626
self.add_shape(self.star1b)
2727
self.add_shape(self.star1c)
2828
self.add_shape(self.star2)
29+
self.proj2D3D = "cylbase"
2930

3031
def update(self, step):
3132
self.star1a.update(step)

xled_plus/samples/day20.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, ctr, sym, colfunc):
1818
self.bgcol = hsl_color(0, 0, -0.5)
1919
self.horizon = 320
2020
self.preferred_frames = 640
21+
self.proj2D3D = "halfsphere"
2122

2223
def create(self):
2324
col = self.colfunc(self.time)

xled_plus/samples/day21.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def moonlit(self, pos):
4545
def update(self, step):
4646
self.phase = (self.phase + 180.0 + self.speed * step) % 360 - 180.0
4747

48-
def get_color(self, coord):
48+
def get_color(self, coord, ind):
4949
if self.is_inside(coord):
5050
if self.moonlit(coord):
5151
return self.light
@@ -62,6 +62,7 @@ def __init__(self, ctr):
6262
self.add_shape(self.moon)
6363
self.preferred_frames = 360
6464
self.preferred_fps = 6
65+
self.proj2D3D = "cylshell"
6566

6667
def whitefunc(self, *args):
6768
r = random()

xled_plus/samples/day22.py

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __init__(self, ctr):
9292
self.shapecolfuncs = [cf1, cf1, cf2, cf2]
9393
self.horizon = 320
9494
self.preferred_frames = 640
95+
self.proj2D3D = "cylshell"
9596

9697
def create(self):
9798
tp = randomdiscrete(self.shapeprobs)

xled_plus/samples/day24.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(self, ctr, cols):
1616
self.blink = hsl_color(0.0, 0.0, 1.0)
1717
self.bgpat = make_random_select_color_pattern(ctr, self.whites)
1818
self.preferred_frames = 640
19+
self.proj2D3D = "cylshell"
1920

2021
def create(self):
2122
tp = int(random() * len(self.colors))

xled_plus/samples/day26.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Day 26 - Random walk with complementary colors
3+
4+
Variant of the Day 25 effect, with a gradient between a random walk
5+
color and its complement.
6+
This is again a continuous effect, not a movie, so when you stop the script
7+
the effect stops.
8+
"""
9+
10+
from xled_plus.samples.sample_setup import *
11+
12+
ctr = setup_control()
13+
oldmode = ctr.get_mode()["mode"]
14+
eff = MeanderingTandemSequence(ctr, gap=0.5, fixangle=0.0)
15+
eff.launch_rt()
16+
print("Started continuous effect - press Return to stop it")
17+
input()
18+
eff.stop_rt()
19+
ctr.set_mode(oldmode)

xled_plus/sequence.py

+55-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from xled_plus.effect_base import Effect
2121
from xled_plus.colormeander import ColorMeander
22-
from xled_plus.pattern import blendcolors
22+
from xled_plus.pattern import blendcolors, dimcolor
2323
from xled_plus.ledcolor import hsl_color
2424
import math as m
2525

@@ -186,13 +186,13 @@ class VaryingAngleSequence(Sequence):
186186
def initialize(self, maxfold):
187187
self.maxfold = maxfold
188188
if self.dim == 3:
189-
self.meander = ColorMeander("sphere")
189+
self.mangle = ColorMeander("sphere")
190190
else:
191-
self.meander = ColorMeander("cylinder")
191+
self.mangle = ColorMeander("cylinder")
192192

193193
def update(self, step):
194-
self.meander.step()
195-
(x, y, z) = self.meander.get_xyz()
194+
self.mangle.step()
195+
(x, y, z) = self.mangle.get_xyz()
196196
if self.dim == 3:
197197
self.vect = (
198198
x * self.maxfold / 2.0,
@@ -219,23 +219,66 @@ def __init__(self, ctr, cols, lens=False, speed=1.0, folds=3.0):
219219

220220

221221
class MeanderingSequence(VaryingAngleSequence):
222-
def __init__(self, ctr):
223-
super(MeanderingSequence, self).__init__(ctr, self.getcolor, 0.0, 0.0, 0.0)
222+
def __init__(self, ctr, fixangle=False):
223+
super(MeanderingSequence, self).__init__(ctr, self.getcolor, 0.0, 1.0, fixangle)
224+
self.fixangle = fixangle
224225
self.initialize(1.0)
225226
self.cm = ColorMeander("sphere")
226-
self.colvec = [self.cm.get()] * 100
227+
self.colvec = [self.cm.get()] * 200
228+
self.iter = 1
227229
self.init_fps(2)
230+
self.preferred_frames = 800
228231

229232
def reset(self, numframes):
230233
self.currpos = 0.5
234+
if numframes:
235+
self.mangle.steplen *= 10
236+
self.mangle.noiselev *= 3
237+
self.iter = 9
238+
self.preferred_fps /= 10
231239

232240
def update(self, step):
233-
super(MeanderingSequence, self).update(step)
234-
self.cm.step()
235-
self.colvec = [self.cm.get()] + self.colvec[:-1]
241+
if self.fixangle is False:
242+
super(MeanderingSequence, self).update(step)
243+
for i in range(self.iter):
244+
self.cm.step()
245+
self.colvec = [self.cm.get()] + self.colvec[:-1]
236246

237247
def getcolor(self, x):
238248
ind = int(x * len(self.colvec) - 0.5)
239249
return self.colvec[min(max(0, ind), len(self.colvec)-1)]
240250

241-
251+
252+
class MeanderingTandemSequence(VaryingAngleSequence):
253+
def __init__(self, ctr, gap=False, fixangle=False):
254+
super(MeanderingTandemSequence, self).__init__(ctr, self.getcolor, 0.0, 1.0, fixangle)
255+
self.initialize(1.0)
256+
self.gap = gap
257+
self.fixangle = fixangle
258+
self.cm = ColorMeander("sphere")
259+
self.init_fps(2)
260+
self.preferred_frames = 800
261+
262+
def reset(self, numframes):
263+
self.currpos = 0.5
264+
if numframes:
265+
self.cm.steplen *= 10
266+
self.cm.noiselev *= 3
267+
self.preferred_fps /= 10
268+
269+
def update(self, step):
270+
if self.fixangle is False:
271+
super(MeanderingTandemSequence, self).update(step)
272+
self.cm.step()
273+
(h, s, l) = self.cm.get_hsl()
274+
self.hsl1 = (h, s, l)
275+
self.hsl2 = ((h + 0.5) % 1.0, s, l)
276+
277+
def getcolor(self, x):
278+
hsl = self.hsl1 if x < 0.5 else self.hsl2
279+
fact = min(1.0, abs(2*x - 1.0) / abs(self.gap)) if self.gap else 1.0
280+
if self.gap >= 0.0:
281+
return hsl_color(hsl[0], hsl[1]*fact, hsl[2])
282+
else:
283+
return hsl_color(hsl[0], hsl[1], hsl[2]) if fact == 1.0 else (0,0,0)
284+

0 commit comments

Comments
 (0)