Skip to content
Snippets Groups Projects
flash.py 985 B
from animation import Animation
from blinkenroom import BLINKENROOM_LOUNGE
import random
from Color import Color
import time

class flash(Animation):

    required_args = {
        "wait_range": [int, 100],
        "stay": [float, 0.1]
    }

    def init_animation(self):
        self.name = "flash"
        self.wait_range = int(self.args["wait_range"])
        self.stay = float(self.args["stay"])
        self.wait = random.randrange(self.wait_range)
        self.blinkenroom = BLINKENROOM_LOUNGE
        self.white = Color((255, 255, 255))

    def cycle(self):
        if self.wait > 0:
            self.wait -= 1
        else:
            index = random.randrange(self.blinkenroom.total_length)
            self.blinkenroom.set_pixel(index, self.white)
            #flushing and setting every pixel to black
            self.blinkenroom.flush(True)
            time.sleep(self.stay)
            self.blinkenroom.flush()
            self.wait = random.randrange(self.wait_range)