sparks.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import hyperion, time, colorsys, random
  2. # Get the parameters
  3. rotationTime = float(hyperion.args.get('rotation-time', 3.0))
  4. sleepTime = float(hyperion.args.get('sleep-time', 0.05))
  5. brightness = float(hyperion.args.get('brightness', 100))/100.0
  6. saturation = float(hyperion.args.get('saturation', 100))/100.0
  7. color = list(hyperion.args.get('color', (255,255,255)))
  8. randomColor = bool(hyperion.args.get('random-color', False))
  9. # Check parameters
  10. rotationTime = max(0.1, rotationTime)
  11. # Initialize the led data
  12. ledData = bytearray()
  13. for i in range(hyperion.ledCount):
  14. ledData += bytearray((0, 0, 0))
  15. # Start the write data loop
  16. while not hyperion.abort():
  17. ledData[:] = bytearray(3*hyperion.ledCount)
  18. for i in range(hyperion.ledCount):
  19. if random.random() < 0.005:
  20. if randomColor:
  21. rgb = colorsys.hsv_to_rgb(random.random(), saturation, brightness)
  22. for n in range(3):
  23. color[n] = int(rgb[n]*255)
  24. for n in range(3):
  25. ledData[i*3+n] = color[n]
  26. hyperion.setColor(ledData)
  27. time.sleep(sleepTime)