2023-11-22 14:45:55 +00:00
|
|
|
#!/usr/bin/env python
|
2023-11-22 15:44:11 +00:00
|
|
|
from ..samplebase import SampleBase
|
2023-11-22 14:45:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PulsingColors(SampleBase):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(PulsingColors, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.offscreen_canvas = self.matrix.CreateFrameCanvas()
|
|
|
|
continuum = 0
|
|
|
|
|
|
|
|
while True:
|
|
|
|
self.usleep(5 * 1000)
|
|
|
|
continuum += 1
|
|
|
|
continuum %= 3 * 255
|
|
|
|
|
|
|
|
red = 0
|
|
|
|
green = 0
|
|
|
|
blue = 0
|
|
|
|
|
|
|
|
if continuum <= 255:
|
|
|
|
c = continuum
|
|
|
|
blue = 255 - c
|
|
|
|
red = c
|
|
|
|
elif continuum > 255 and continuum <= 511:
|
|
|
|
c = continuum - 256
|
|
|
|
red = 255 - c
|
|
|
|
green = c
|
|
|
|
else:
|
|
|
|
c = continuum - 512
|
|
|
|
green = 255 - c
|
|
|
|
blue = c
|
|
|
|
|
|
|
|
self.offscreen_canvas.Fill(red, green, blue)
|
|
|
|
self.offscreen_canvas = self.matrix.SwapOnVSync(self.offscreen_canvas)
|
|
|
|
|
|
|
|
# Main function
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pulsing_colors = PulsingColors()
|
|
|
|
if (not pulsing_colors.process()):
|
|
|
|
pulsing_colors.print_help()
|