mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor Python for 3.12 integration (#1807)
* Correct JS requestConfig call
* Update requestWriteConfig to new API format
* Add hyperion-light and bare-minimum preset scenarios
* Refactor Python
* Windows add bcrypt until mbedtls is fixed
(https://github.com/Mbed-TLS/mbedtls/pull/9554)
* Corrections
* Use ScreenCaptureKit under macOS 15 and above
* ReSigning macOS package
* Python 3.11.10 test
* Revert "Python 3.11.10 test"
This reverts commit ee921e4f12
.
* Handle defined exits from python scripts
* Update change.log
* CodeQL findings
---------
Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
# 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
|
||||
|
||||
# Get parameters
|
||||
@@ -7,6 +5,11 @@ 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))
|
||||
|
||||
# Ensure that the range for pixel indices stays within bounds
|
||||
maxPixelIndex = hyperion.ledCount - 1
|
||||
if trailLength > maxPixelIndex or explodeRadius > maxPixelIndex:
|
||||
exit(f"Error: Color length ({trailLength}) and detonation range ({explodeRadius}) must be less than number of LEDs configured ({hyperion.ledCount})")
|
||||
|
||||
# Create additional variables
|
||||
increment = None
|
||||
projectiles = []
|
||||
@@ -14,47 +17,64 @@ projectiles = []
|
||||
# Initialize the led data
|
||||
ledData = bytearray()
|
||||
for i in range(hyperion.ledCount):
|
||||
ledData += bytearray((0,0,0))
|
||||
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)
|
||||
if len(projectiles) != 2:
|
||||
projectiles = [
|
||||
[0, 1, random.uniform(0.0, 1.0)], # Start positions of projectiles
|
||||
[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])
|
||||
# Backup the LED data
|
||||
ledDataBuf = ledData[:]
|
||||
for i, v in enumerate(projectiles):
|
||||
# Update projectile positions
|
||||
projectiles[i][0] = projectiles[i][0] + projectiles[i][1]
|
||||
|
||||
for t in range(0, trailLength):
|
||||
# Calculate pixel index for the trail
|
||||
pixel = v[0] - v[1] * t
|
||||
if pixel < 0:
|
||||
pixel += hyperion.ledCount
|
||||
if pixel >= hyperion.ledCount:
|
||||
pixel -= hyperion.ledCount
|
||||
|
||||
hyperion.setColor(ledDataBuf[-increment:] + ledDataBuf[:-increment])
|
||||
# Make sure pixel is within bounds
|
||||
if pixel < 0 or pixel >= hyperion.ledCount:
|
||||
continue
|
||||
|
||||
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])
|
||||
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])
|
||||
time.sleep(sleepTime)
|
||||
hyperion.setColor(ledDataBuf[-increment:] + ledDataBuf[:-increment])
|
||||
|
||||
projectiles.remove(p1)
|
||||
projectiles.remove(p2)
|
||||
# Check for collision and handle explosion
|
||||
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):
|
||||
# Check if pixel is out of bounds
|
||||
if pixel < 0 or pixel >= hyperion.ledCount:
|
||||
continue
|
||||
|
||||
time.sleep(sleepTime)
|
||||
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)
|
||||
|
Reference in New Issue
Block a user