|
6 | 6 | # Get the parameters
|
7 | 7 | rotationTime = float(hyperion.args.get('rotationTime', 20.0))
|
8 | 8 | 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)) |
10 | 10 | blobs = int(hyperion.args.get('blobs', 5))
|
11 | 11 | 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) |
12 | 28 |
|
13 | 29 | # Check parameters
|
14 | 30 | rotationTime = max(0.1, rotationTime)
|
15 | 31 | hueChange = max(0.0, min(abs(hueChange), .5))
|
16 | 32 | blobs = max(1, blobs)
|
| 33 | +baseColorChangeRate = max(0, baseColorChangeRate) # > 0 |
17 | 34 |
|
18 | 35 | # Calculate the color data
|
19 | 36 | baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
|
|
27 | 44 | sleepTime = 0.1
|
28 | 45 | amplitudePhaseIncrement = blobs * math.pi * sleepTime / rotationTime
|
29 | 46 | colorDataIncrement = 3
|
| 47 | +baseColorChangeRate /= sleepTime |
30 | 48 |
|
31 | 49 | # Switch direction if needed
|
32 | 50 | if reverse:
|
|
39 | 57 | # Start the write data loop
|
40 | 58 | amplitudePhase = 0.0
|
41 | 59 | rotateColors = False
|
| 60 | +baseColorChangeStepCount = 0 |
| 61 | +baseHSVValue = baseHsv[0] |
| 62 | +numberOfRotates = 0 |
| 63 | + |
42 | 64 | 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