From 4c0c102f2c394a54f8853bfea1dd2d1c196a7ee6 Mon Sep 17 00:00:00 2001 From: Paulchen-Panther Date: Sun, 10 Nov 2019 17:24:04 +0100 Subject: [PATCH] New effect collision Signed-off-by: Paulchen-Panther --- assets/webconfig/i18n/de.json | 3 ++ assets/webconfig/i18n/en.json | 3 ++ effects/collision.json | 10 +++++ effects/collision.py | 60 ++++++++++++++++++++++++++++ effects/schema/collision.schema.json | 40 +++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 effects/collision.json create mode 100644 effects/collision.py create mode 100644 effects/schema/collision.schema.json diff --git a/assets/webconfig/i18n/de.json b/assets/webconfig/i18n/de.json index 35ac5cfb..4dca5fe7 100644 --- a/assets/webconfig/i18n/de.json +++ b/assets/webconfig/i18n/de.json @@ -690,6 +690,9 @@ "edt_eff_trails_header_desc": "In verschiedenen Farben, wünsch dir was!", "edt_eff_flag_header": "Flaggen", "edt_eff_flag_header_desc": "Verpasse deinen LEDs die Farben deines Landes. Du kannst mehr als eine Flagge auswählen, je nach Intervall werden diese dann abwechselnd angezeigt.", + "edt_eff_collision_header": "Farbkollision", + "edt_eff_collision_header_desc": "Zwei Farbprojektile werden von zufälligen Positionen gesendet und kollidieren miteinander", + "edt_eff_explodeRadius": "Detonationsreichweite ", "edt_eff_enum_all": "Alle", "edt_eff_enum_all-together": "Alle zusammen", "edt_eff_enum_list": "LED Liste", diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 79f70e30..f87c7457 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -689,6 +689,9 @@ "edt_eff_trails_header_desc" : "Colored stars that fall from top to bottom", "edt_eff_flag_header" : "Flags", "edt_eff_flag_header_desc" : "Let your leds shine bright in the colors of your country. You could select more than one flag, they will change based on interval time.", + "edt_eff_collision_header": "color collision", + "edt_eff_collision_header_desc": "Two color projectiles are sent from random positions and collide with each other", + "edt_eff_explodeRadius": "Detonation Range ", "edt_eff_enum_all" : "All", "edt_eff_enum_all-together" : "All together", "edt_eff_enum_list" : "LED List", diff --git a/effects/collision.json b/effects/collision.json new file mode 100644 index 00000000..c0434c3b --- /dev/null +++ b/effects/collision.json @@ -0,0 +1,10 @@ +{ + "name" : "Collision", + "script" : "collision.py", + "args" : + { + "speed" : 100, + "trailLength" : 5, + "explodeRadius" : 8 + } +} diff --git a/effects/collision.py b/effects/collision.py new file mode 100644 index 00000000..476b7b4c --- /dev/null +++ b/effects/collision.py @@ -0,0 +1,60 @@ +# Two projectiles are sent from random positions and collide with each other +# Template from https://github.com/nickpesce/lit/blob/master/lit/effects/collision.py +import hyperion, time, colorsys, random, math + +# Get parameters +sleepTime = max(0.02, float(hyperion.args.get('speed', 100))/1000.0) +trailLength = max(3, int(hyperion.args.get('trailLength', 5))) +explodeRadius = int(hyperion.args.get('explodeRadius', 8)) + +# Create additional variables +increment = None +projectiles = [] + +# Initialize the led data +ledData = bytearray() +for i in range(hyperion.ledCount): + ledData += bytearray((0,0,0)) + +# Start the write data loop +while not hyperion.abort(): + if (len(projectiles) != 2): + projectiles = [ [0, 1, random.uniform(0.0, 1.0)], [hyperion.ledCount-1, -1, random.uniform(0.0, 1.0)] ] + increment = -random.randint(0, hyperion.ledCount-1) if random.choice([True, False]) else random.randint(0, hyperion.ledCount-1) + + ledDataBuf = ledData[:] + for i, v in enumerate(projectiles): + projectiles[i][0] = projectiles[i][0]+projectiles[i][1] + for t in range(0, trailLength): + pixel = v[0] - v[1]*t + if pixel + 2 < 0: + pixel += hyperion.ledCount + if pixel + 2 > hyperion.ledCount-1: + pixel -= hyperion.ledCount-1 + rgb = colorsys.hsv_to_rgb(v[2], 1, (trailLength - 1.0*t)/trailLength) + ledDataBuf[3*pixel ] = int(255*rgb[0]) + ledDataBuf[3*pixel + 1] = int(255*rgb[1]) + ledDataBuf[3*pixel + 2] = int(255*rgb[2]) + + hyperion.setColor(ledDataBuf[-increment:] + ledDataBuf[:-increment]) + + for i1, p1 in enumerate(projectiles): + for i2, p2 in enumerate(projectiles): + if (p1 is not p2): + prev1 = p1[0] - p1[1] + prev2 = p2[0] - p2[1] + if (prev1 - prev2 < 0) != (p1[0] - p2[0] < 0): + for d in range(0, explodeRadius): + for pixel in range(p1[0] - d, p1[0] + d): + rgb = colorsys.hsv_to_rgb(random.choice([p1[2], p2[2]]), 1, (1.0 * explodeRadius - d) / explodeRadius) + ledDataBuf[3*pixel ] = int(255*rgb[0]) + ledDataBuf[3*pixel + 1] = int(255*rgb[1]) + ledDataBuf[3*pixel + 2] = int(255*rgb[2]) + + hyperion.setColor(ledDataBuf[-increment:] + ledDataBuf[:-increment]) + time.sleep(sleepTime) + + projectiles.remove(p1) + projectiles.remove(p2) + + time.sleep(sleepTime) diff --git a/effects/schema/collision.schema.json b/effects/schema/collision.schema.json new file mode 100644 index 00000000..448483aa --- /dev/null +++ b/effects/schema/collision.schema.json @@ -0,0 +1,40 @@ +{ + "type":"object", + "script" : "collision.py", + "title":"edt_eff_collision_header", + "required":true, + "properties":{ + "speed": { + "type": "number", + "title":"edt_eff_speed", + "default": 100, + "minimum" : 100, + "append" : "edt_append_ms", + "propertyOrder" : 1 + }, + "trailLength" : + { + "type": "integer", + "title":"edt_eff_colorcount", + "default": 5, + "minimum" : 3, + "maximum" : 100, + "step" : 1, + "append" : "edt_append_pixel", + "propertyOrder" : 2 + }, + "explodeRadius" : + { + "type": "integer", + "title":"edt_eff_explodeRadius", + "default": 8, + "minimum" : 5, + "maximum" : 100, + "step" : 1, + "append" : "edt_append_pixel", + "propertyOrder" : 3 + } + + }, + "additionalProperties": false +}