Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 8c5769e

Browse files
committed
Merge pull request #109 from Fabi1080/feature/moodblobs_upgrade
Effect mood blob upgrade
2 parents deb8e61 + 0c7a2ad commit 8c5769e

File tree

4 files changed

+121
-20
lines changed

4 files changed

+121
-20
lines changed

effects/mood-blobs-cold.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name" : "Cold mood blobs",
3+
"script" : "mood-blobs.py",
4+
"args" :
5+
{
6+
"rotationTime" : 60.0,
7+
"color" : [0,0,255],
8+
"hueChange" : 30.0,
9+
"blobs" : 5,
10+
"reverse" : false,
11+
"baseChange" : true,
12+
"baseColorRangeLeft" : 160,
13+
"baseColorRangeRight" : 320,
14+
"baseColorChangeRate" : 2.0
15+
}
16+
}

effects/mood-blobs-full.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name" : "Full color mood blobs",
3+
"script" : "mood-blobs.py",
4+
"args" :
5+
{
6+
"rotationTime" : 60.0,
7+
"color" : [0,0,255],
8+
"hueChange" : 30.0,
9+
"blobs" : 5,
10+
"reverse" : false,
11+
"baseChange" : true,
12+
"baseColorRangeLeft" : 0,
13+
"baseColorRangeRight" : 360,
14+
"baseColorChangeRate" : 0.2
15+
}
16+
}

effects/mood-blobs-warm.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name" : "Warm mood blobs",
3+
"script" : "mood-blobs.py",
4+
"args" :
5+
{
6+
"rotationTime" : 60.0,
7+
"color" : [255,0,0],
8+
"hueChange" : 30.0,
9+
"blobs" : 5,
10+
"reverse" : false,
11+
"baseChange" : true,
12+
"baseColorRangeLeft" : 333,
13+
"baseColorRangeRight" : 151,
14+
"baseColorChangeRate" : 2.0
15+
}
16+
}

effects/mood-blobs.py

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,31 @@
66
# Get the parameters
77
rotationTime = float(hyperion.args.get('rotationTime', 20.0))
88
color = hyperion.args.get('color', (0,0,255))
9-
hueChange = float(hyperion.args.get('hueChange', 60.0)) / 360.0
9+
hueChange = float(hyperion.args.get('hueChange', 60.0))
1010
blobs = int(hyperion.args.get('blobs', 5))
1111
reverse = bool(hyperion.args.get('reverse', False))
12+
baseColorChange = bool(hyperion.args.get('baseChange', False))
13+
baseColorRangeLeft = float(hyperion.args.get('baseColorRangeLeft',0.0)) # Degree
14+
baseColorRangeRight = float(hyperion.args.get('baseColorRangeRight',360.0)) # Degree
15+
baseColorChangeRate = float(hyperion.args.get('baseColorChangeRate',10.0)) # Seconds for one Degree
16+
17+
# switch baseColor change off if left and right are too close together to see a difference in color
18+
if (baseColorRangeRight > baseColorRangeLeft and (baseColorRangeRight - baseColorRangeLeft) < 10) or \
19+
(baseColorRangeLeft > baseColorRangeRight and ((baseColorRangeRight + 360) - baseColorRangeLeft) < 10):
20+
baseColorChange = False
21+
22+
# 360 -> 1
23+
fullColorWheelAvailable = (baseColorRangeRight % 360) == (baseColorRangeLeft % 360)
24+
baseColorChangeIncreaseValue = 1.0 / 360.0 # 1 degree
25+
hueChange /= 360.0
26+
baseColorRangeLeft = (baseColorRangeLeft / 360.0)
27+
baseColorRangeRight = (baseColorRangeRight / 360.0)
1228

1329
# Check parameters
1430
rotationTime = max(0.1, rotationTime)
1531
hueChange = max(0.0, min(abs(hueChange), .5))
1632
blobs = max(1, blobs)
33+
baseColorChangeRate = max(0, baseColorChangeRate) # > 0
1734

1835
# Calculate the color data
1936
baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
@@ -27,6 +44,7 @@
2744
sleepTime = 0.1
2845
amplitudePhaseIncrement = blobs * math.pi * sleepTime / rotationTime
2946
colorDataIncrement = 3
47+
baseColorChangeRate /= sleepTime
3048

3149
# Switch direction if needed
3250
if reverse:
@@ -39,23 +57,58 @@
3957
# Start the write data loop
4058
amplitudePhase = 0.0
4159
rotateColors = False
60+
baseColorChangeStepCount = 0
61+
baseHSVValue = baseHsv[0]
62+
numberOfRotates = 0
63+
4264
while not hyperion.abort():
43-
# Calculate new colors
44-
for i in range(hyperion.ledCount):
45-
amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount))
46-
colors[3*i+0] = int(colorData[3*i+0] * amplitude)
47-
colors[3*i+1] = int(colorData[3*i+1] * amplitude)
48-
colors[3*i+2] = int(colorData[3*i+2] * amplitude)
49-
50-
# set colors
51-
hyperion.setColor(colors)
52-
53-
# increment the phase
54-
amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi)
55-
56-
if rotateColors:
57-
colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement]
58-
rotateColors = not rotateColors
59-
60-
# sleep for a while
61-
time.sleep(sleepTime)
65+
66+
# move the basecolor
67+
if baseColorChange:
68+
# every baseColorChangeRate seconds
69+
if baseColorChangeStepCount >= baseColorChangeRate:
70+
baseColorChangeStepCount = 0
71+
# cyclic increment when the full colorwheel is available, move up and down otherwise
72+
if fullColorWheelAvailable:
73+
baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % baseColorRangeRight
74+
else:
75+
# switch increment direction if baseHSV <= left or baseHSV >= right
76+
if baseColorChangeIncreaseValue < 0 and baseHSVValue > baseColorRangeLeft and (baseHSVValue + baseColorChangeIncreaseValue) <= baseColorRangeLeft:
77+
baseColorChangeIncreaseValue = abs(baseColorChangeIncreaseValue)
78+
elif baseColorChangeIncreaseValue > 0 and baseHSVValue < baseColorRangeRight and (baseHSVValue + baseColorChangeIncreaseValue) >= baseColorRangeRight :
79+
baseColorChangeIncreaseValue = -abs(baseColorChangeIncreaseValue)
80+
81+
baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % 1.0
82+
83+
# update color values
84+
colorData = bytearray()
85+
for i in range(hyperion.ledCount):
86+
hue = (baseHSVValue + hueChange * math.sin(2*math.pi * i / hyperion.ledCount)) % 1.0
87+
rgb = colorsys.hsv_to_rgb(hue, baseHsv[1], baseHsv[2])
88+
colorData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
89+
90+
# set correct rotation after reinitialisation of the array
91+
colorData = colorData[-colorDataIncrement*numberOfRotates:] + colorData[:-colorDataIncrement*numberOfRotates]
92+
93+
baseColorChangeStepCount += 1
94+
95+
# Calculate new colors
96+
for i in range(hyperion.ledCount):
97+
amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount))
98+
colors[3*i+0] = int(colorData[3*i+0] * amplitude)
99+
colors[3*i+1] = int(colorData[3*i+1] * amplitude)
100+
colors[3*i+2] = int(colorData[3*i+2] * amplitude)
101+
102+
# set colors
103+
hyperion.setColor(colors)
104+
105+
# increment the phase
106+
amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi)
107+
108+
if rotateColors:
109+
colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement]
110+
numberOfRotates = (numberOfRotates + 1) % hyperion.ledCount
111+
rotateColors = not rotateColors
112+
113+
# sleep for a while
114+
time.sleep(sleepTime)

0 commit comments

Comments
 (0)