From fbcc46ed28ce0d4b9a87ec080c4f71a952fc5830 Mon Sep 17 00:00:00 2001 From: Paulchen Panther Date: Thu, 20 Dec 2018 14:49:34 +0100 Subject: [PATCH] Wave effect --- effects/Seawaves.json | 47 ++++++++++++++++++++++++++ effects/Waves.json | 8 +++++ effects/waves.py | 77 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 effects/Seawaves.json create mode 100644 effects/Waves.json create mode 100644 effects/waves.py diff --git a/effects/Seawaves.json b/effects/Seawaves.json new file mode 100644 index 00000000..cf3c30c9 --- /dev/null +++ b/effects/Seawaves.json @@ -0,0 +1,47 @@ +{ + "args": { + "center_x": 1.25, + "center_y": -0.25, + "colors": [ + [ + 8, + 0, + 255 + ], + [ + 0, + 161, + 255 + ], + [ + 0, + 222, + 255 + ], + [ + 0, + 153, + 255 + ], + [ + 38, + 0, + 255 + ], + [ + 0, + 199, + 255 + ] + ], + "random-center": false, + "reverse": false, + "reverse_time": 0, + "rotation_time": 60, + "smoothing-custom-settings": true, + "smoothing-time_ms": 200, + "smoothing-updateFrequency": 25 + }, + "name": "Sea waves", + "script": "waves.py" +} diff --git a/effects/Waves.json b/effects/Waves.json new file mode 100644 index 00000000..b4ae8b14 --- /dev/null +++ b/effects/Waves.json @@ -0,0 +1,8 @@ +{ + "name" : "Waves with Color", + "script" : "waves.py", + "args" : + { + "reverse" : false + } +} diff --git a/effects/waves.py b/effects/waves.py new file mode 100644 index 00000000..b253ec79 --- /dev/null +++ b/effects/waves.py @@ -0,0 +1,77 @@ +import hyperion, time, math, random + +randomCenter = bool(hyperion.args.get('random-center', False)) +centerX = float(hyperion.args.get('center_x', -0.15)) +centerY = float(hyperion.args.get('center_y', -0.25)) +rotationTime = float(hyperion.args.get('rotation_time', 90)) +colors = hyperion.args.get('colors', ((255,0,0),(255,255,0),(0,255,0),(0,255,255),(0,0,255),(255,0,255))) +reverse = bool(hyperion.args.get('reverse', False)) +reverseTime = int(hyperion.args.get('reverse_time', 0)) +#rotate = bool(hyperion.args.get('rotate', True)) +positions = [] + +# calc center if random +if randomCenter: + centerX = random.uniform(0.0, 1.0) + centerY = random.uniform(0.0, 1.0) + +rCenterX = int(round(float(hyperion.imageWidth())*centerX)) +rCenterY = int(round(float(hyperion.imageHeight())*centerY)) + +#calc interval +sleepTime = max(1/(255/rotationTime), 0.016) + +#calc diagonal +if centerX < 0.5: + cX = 1.0-centerX +else: + cX = 0.0+centerX + +if centerY < 0.5: + cY = 1.0-centerY +else: + cY = 0.0+centerY + +diag = int(round(math.sqrt(((cX*hyperion.imageWidth())**2)+((cY*hyperion.imageHeight())**2)))) +# some diagonal overhead +diag = int(diag*1.3) + +# calc positions +pos = 0 +step = int(255/len(colors)) +for entry in colors: + positions.append(pos) + pos += step + +# target time +targetTime = time.time()+float(reverseTime) + +#hyperion.imageCOffset(int(hyperion.imageWidth()/2), int(hyperion.imageHeight()/2)) + +while not hyperion.abort(): + # verify reverseTime, randomize reverseTime based on reverseTime up to reversedTime*2 + if reverseTime >= 1: + now = time.time() + if now > targetTime: + reverse = not reverse + targetTime = time.time()+random.uniform(float(reverseTime), float(reverseTime*2.0)) + # apply rotate + #if rotate: + # hyperion.imageCRotate(1) + # prepare bytearray with colors and positions + gradientBa = bytearray() + it = 0 + for color in colors: + gradientBa += bytearray((positions[it],color[0],color[1],color[2])) + it += 1 + + hyperion.imageRadialGradient(rCenterX,rCenterY, diag, gradientBa,0) + + # increment positions + for i, pos in enumerate(positions): + if reverse: + positions[i] = pos - 1 if pos >= 1 else 255 + else: + positions[i] = pos + 1 if pos <= 254 else 0 + hyperion.imageShow() + time.sleep(sleepTime)