Skip to content

Commit a1b8247

Browse files
committed
Dec 22 daily effect
1 parent 552ff14 commit a1b8247

File tree

3 files changed

+140
-11
lines changed

3 files changed

+140
-11
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.1.22'
1+
__version__ = '0.1.23'
22

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

xled_plus/samples/day20.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, ctr, sym, colfunc):
1515
self.freq = 0.6
1616
self.symang = m.pi / sym
1717
self.colfunc = colfunc
18-
self.bgpat = ctr.make_solid_pattern(hsl_color(0,0,-0.5))
18+
self.bgcol = hsl_color(0, 0, -0.5)
1919
self.horizon = 320
2020
self.preferred_frames = 640
2121

@@ -28,9 +28,9 @@ def create(self):
2828
vec = (m.sin(angle), m.cos(angle))
2929
cent = (-vec[0] * 1.5 + vec[1] * offset, -vec[1] * 1.5 - vec[0] * offset + 0.5)
3030
vel = (vec[0] * speed, vec[1] * speed)
31-
nstep = int(2.0 / speed)
32-
#shape = Blob(cent, rad, col)
33-
shape = Ellipse(cent, 0.0, rad, rad, col)
31+
nstep = int(3.0 / speed)
32+
shape = Blob(cent, rad, col)
33+
#shape = Ellipse(cent, 0.0, rad, rad, col)
3434
shape.set_depth(0.0)
3535
shape.set_speed(vel[0], vel[1])
3636
shape.duetime = self.time + nstep
@@ -42,12 +42,20 @@ def get_color(self, coord, ind):
4242
a = abs((a % (2 * self.symang)) - self.symang)
4343
return super(SoftKaleidoScene, self).get_color((m.sin(a) * r, m.cos(a) * r), ind)
4444

45-
def getnext(self):
46-
pat1 = super(SoftKaleidoScene, self).getnext()
47-
vec = self.getoccupancy()
48-
pat = [pat1[i] if vec[i] else self.bgpat[i] for i in range(self.ctr.num_leds)]
49-
return pat
45+
def blend_colors(self, colors):
46+
cols = colors
47+
br = list(map(lambda rgb: color_brightness(*rgb), colors))
48+
maxbr = max(br) if br else 0.0
49+
sumbr = sum(br) if br else 0.0
50+
bgbr = color_brightness(*self.bgcol)
51+
if maxbr < bgbr:
52+
delta = (bgbr - maxbr) / bgbr
53+
sumbr += (bgbr - maxbr)
54+
maxbr = bgbr
55+
cols = cols + [tuple(map(lambda x: x*delta, self.bgcol))]
56+
sumcol = tuple(map(lambda *args: int(round(sum(args) * maxbr / sumbr)), *cols))
57+
return sumcol
5058

5159
ctr = setup_control()
5260
ctr.adjust_layout_aspect(1.0) # How many times wider than high is the led installation?
53-
SoftKaleidoScene(ctr, 3, random_hsl_color_func(light=0.0)).launch_movie()
61+
SoftKaleidoScene(ctr, 5, random_hsl_color_func(light=0.0)).launch_movie()

xled_plus/samples/day22.py

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
"""
2+
Day 22 - Snowflakes
3+
4+
Falling snowflakes against a purple-blue background.
5+
Mimics the snowfall effect you can download with the app.
6+
"""
7+
8+
from xled_plus.samples.sample_setup import *
9+
10+
x = 0.75 ** 0.5
11+
12+
snowflake1 = [
13+
([0.0, -1.0], [0.0, 1.0], 0.0),
14+
([-x, -0.5], [x, 0.5], 0.0),
15+
([-x, 0.5], [x, -0.5], 0.0),
16+
([0.0, -0.7], [-0.3*x, -0.85], 0.0),
17+
([0.0, -0.7], [0.3*x, -0.85], 0.0),
18+
([0.0, 0.7], [-0.3*x, 0.85], 0.0),
19+
([0.0, 0.7], [0.3*x, 0.85], 0.0),
20+
([-0.7*x, -0.35], [-0.7*x, -0.65], 0.0),
21+
([-0.7*x, 0.35], [-0.7*x, 0.65], 0.0),
22+
([0.7*x, -0.35], [0.7*x, -0.65], 0.0),
23+
([0.7*x, 0.35], [0.7*x, 0.65], 0.0),
24+
([-0.7*x, -0.35], [-x, -0.2], 0.0),
25+
([-0.7*x, 0.35], [-x, 0.2], 0.0),
26+
([0.7*x, -0.35], [x, -0.2], 0.0),
27+
([0.7*x, 0.35], [x, 0.2], 0.0),
28+
]
29+
30+
snowflake2 = [
31+
([0.0, -1.0], [0.0, 1.0], 0.0),
32+
([-x, -0.5], [x, 0.5], 0.0),
33+
([-x, 0.5], [x, -0.5], 0.0),
34+
([0.0, -0.5], [-0.5*x, -0.25], 0.0),
35+
([0.0, -0.5], [0.5*x, -0.25], 0.0),
36+
([0.0, 0.5], [-0.5*x, 0.25], 0.0),
37+
([0.0, 0.5], [0.5*x, 0.25], 0.0),
38+
([0.5*x, 0.25], [0.5*x, -0.25], 0.0),
39+
([-0.5*x, 0.25], [-0.5*x, -0.25], 0.0),
40+
]
41+
42+
snowflake3 = [
43+
([0.0, -0.5], [0.0, 0.5], 0.0),
44+
([-0.5*x, -0.25], [0.5*x, 0.25], 0.0),
45+
([-0.5*x, 0.25], [0.5*x, -0.25], 0.0),
46+
]
47+
48+
snowflake4 = [
49+
([0.0, -0.3], [-0.3*x, -0.15], 0.0),
50+
([0.0, -0.3], [0.3*x, -0.15], 0.0),
51+
([0.0, 0.3], [-0.3*x, 0.15], 0.0),
52+
([0.0, 0.3], [0.3*x, 0.15], 0.0),
53+
([0.3*x, 0.15], [0.3*x, -0.15], 0.0),
54+
([-0.3*x, 0.15], [-0.3*x, -0.15], 0.0),
55+
]
56+
57+
class Snowflake(Lineart2D):
58+
def __init__(self, segs, pos, angle, size, color):
59+
super(Snowflake, self).__init__()
60+
for seg in segs:
61+
self.add_segment(*seg)
62+
self.color = color
63+
self.size = size
64+
self.off = [0.0, 0.0]
65+
self.angle = 0.0
66+
self.speed = (0.0, 0.0)
67+
self.torque = 0.0
68+
self.change_pos(pos)
69+
self.change_angle(angle)
70+
71+
def change_angle(self, deltaangle):
72+
self.angle += deltaangle
73+
ca = m.cos(self.angle * m.pi / 180.0) / self.size
74+
sa = m.sin(self.angle * m.pi / 180.0) / self.size
75+
self.mat = [[ca, sa], [-sa, ca]]
76+
77+
def change_pos(self, delta):
78+
self.off = [self.off[0] - delta[0], self.off[1] - delta[1]]
79+
80+
def update(self, step):
81+
self.change_pos((step * self.speed[0], step * self.speed[1]))
82+
self.change_angle(step * self.torque)
83+
84+
class SnowingScene(MovingShapesScene):
85+
def __init__(self, ctr):
86+
super(SnowingScene, self).__init__(ctr)
87+
self.freq = 0.6
88+
self.shapetypes = [snowflake1, snowflake2, snowflake3, snowflake4]
89+
self.shapeprobs = [0.15, 0.15, 0.3, 0.4]
90+
cf1 = random_hsl_color_func(hue=[0.06,0.12], sat=1.0, light=[0.2,0.6])
91+
cf2 = random_hsl_color_func(hue=[0.96,0.06], sat=0.7, light=0.0)
92+
self.shapecolfuncs = [cf1, cf1, cf2, cf2]
93+
self.preferred_frames = 640
94+
95+
def create(self):
96+
tp = randomdiscrete(self.shapeprobs)
97+
col = self.shapecolfuncs[tp]()
98+
dist = 1.0 + random() + (tp // 2)*2
99+
speed = 0.02 / dist
100+
rot = (random() - 0.5) * 6.0
101+
offset = (random() * 2 - 1.0, 1.5)
102+
vec = (0.0, -speed)
103+
sf = Snowflake(self.shapetypes[tp], offset, 0.0, 0.3, col)
104+
sf.speed = vec
105+
sf.torque = rot
106+
sf.set_depth(dist)
107+
sf.lw = 0.15
108+
sf.duetime = self.time + int(3.0 / speed)
109+
return sf
110+
111+
def getnext(self):
112+
pat1 = super(SnowingScene, self).getnext()
113+
hue = (0.78 + 0.44 * abs(0.5 - (float(self.time) / 160) % 1.0)) % 1.0
114+
patbg = ctr.make_layout_pattern(lambda pos: hsl_color(hue, 1.0, -0.92), style="centered")
115+
vec = self.getoccupancy()
116+
pat = [pat1[i] if vec[i] else patbg[i] for i in range(self.ctr.num_leds)]
117+
return pat
118+
119+
ctr = setup_control()
120+
ctr.adjust_layout_aspect(1.0) # How many times wider than high is the led installation?
121+
SnowingScene(ctr).launch_movie()

0 commit comments

Comments
 (0)