コード例 #1
0
    class BreatheFX(BaseFX):
        description = Unicode('Colors pulse in and out')
        colors = ColorSchemeTrait(minlen=1,
                                  maxlen=3,
                                  default_value=('red', 'green',
                                                 'blue')).tag(config=True)

        def apply(self) -> bool:
            """
            Breathing color effect. Accepts up to three colors on v2 hardware

            :param color1: Primary color
            :param color2: Secondary color
            :param color3: Tertiary color
            :param preset: Predefinied color pair

            :return True if successful:
            """
            bits = EffectBits()
            bits.on = True
            bits.sync = True
            if len(self.colors) == 3:
                bits.breathe_triple = True
            elif len(self.colors) == 2:
                bits.breathe_double = True
            elif len(self.colors) == 1:
                bits.breathe_single = True

            with self._driver.device_open():
                if self._driver._set_rgb(*self.colors):
                    return self._driver._set_led_mode(bits)

            return False
コード例 #2
0
class Plasma(Renderer):
    """
    Draws a old-school plasma effect
    """

    # meta
    meta = RendererMeta('Plasma', 'Colorful moving blobs of plasma',
                        'Steve Kondik', 'v1.0')

    # configurable traits
    color_scheme = ColorSchemeTrait(minlen=2, \
            default_value=[*ColorScheme.Qap.value]).tag(config=True)
    preset = ColorPresetTrait(ColorScheme, \
            default_value=ColorScheme.Qap).tag(config=True)
    gradient_length = Int(default_value=360, min=0).tag(config=True)

    def __init__(self, *args, **kwargs):
        super(Plasma, self).__init__(*args, **kwargs)

        self._gradient = None
        self._start_time = 0
        self.fps = 15

    def _gen_gradient(self):
        self._gradient = ColorUtils.gradient(self.gradient_length,
                                             *self.color_scheme)

    @observe('color_scheme', 'gradient_length', 'preset')
    def _scheme_changed(self, changed):
        with self.hold_trait_notifications():
            self.logger.debug("Parameters changed: %s", changed)
            if changed.name == 'preset':
                self.color_scheme.clear()
                self.color_scheme = list(changed.new.value)
            self._gen_gradient()

    def init(self, frame):
        self._start_time = time.time()
        self._gen_gradient()
        return True

    async def draw(self, layer, timestamp):
        duration = timestamp - self._start_time

        draw_plasma(layer.width, layer.height, layer.matrix, duration,
                    self._gradient)

        return True
コード例 #3
0
    class BreatheFX(BaseFX):
        description = Unicode('Colors pulse in and out')
        colors = ColorSchemeTrait(minlen=0, maxlen=2).tag(config=True)

        def apply(self) -> bool:
            """
            Activate the "breathe" effect. Colors pulse in and out.

            This effect allows up to two (optional) colors. If no colors are
            specified, random colors will be used.

            :param color1: First color
            :param color2: Second color
            :param preset: Predefined color pair, invalid when color1/color2 is supplied

            :return: True if successful
            """
            return self._fxmod.set_effect(FX.BREATHE, Mode(len(self.colors)),
                                          *self.colors)
コード例 #4
0
    class StarlightFX(BaseFX):
        description = Unicode('Keys sparkle with color')
        colors = ColorSchemeTrait(minlen=0, maxlen=2).tag(config=True)
        speed = Int(default_value=1, min=1, max=4).tag(config=True)

        def apply(self) -> bool:
            """
            Activate the "starlight" effect. Colors sparkle across the device.

            This effect allows up to two (optional) colors. If no colors are
            specified, random colors will be used.

            :param color1: First color
            :param color2: Second color
            :param speed: Speed of the effect
            :param preset: Predefined color pair, invalid when color1/color2 is supplied

            :return: True if successful
            """
            return self._fxmod.set_effect(FX.STARLIGHT, Mode(len(self.colors)),
                                          self.speed, *self.colors)