예제 #1
0
    def _transition(self, duration, color, brightness):
        """ Transition.

        :param duration: Time to transition.
        :param color: Transition to this color.
        :param brightness: Transition to this brightness.
        """
        # Calculate brightness steps.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness,
                            brightness, BRIGHTNESS_STEPS)
        # Calculate color steps.
        c_steps = 0
        if color is not None:
            c_steps = abs(util.rgb_to_hue(*self.color)
                          - util.rgb_to_hue(*color))
        # Compute ideal step amount.
        total = c_steps + b_steps
        # Calculate wait.
        wait = self._wait(duration, total)
        # Scale down steps if no wait time.
        if wait == 0:
            total = self._scaled_steps(duration, total, total)
        # Calculate start and end.
        if total != b_steps:
            c_start = rgb_to_hsv(*self._color)
            c_end = rgb_to_hsv(*color)
        b_start = self.brightness
        # Perform transition.
        j = 0
        for i in range(total):
            # Brightness.
            if (b_steps > 0
                    and i % math.ceil(total/b_steps) == 0):
                j += 1
                self.brightness = util.transition(j, b_steps,
                                                  b_start, brightness)
            # Color.
            elif c_steps > 0:
                rgb = hsv_to_rgb(*util.transition3(i - j + 1,
                                                   total - b_steps,
                                                   c_start, c_end))
                self.color = Color(*rgb)
            # Wait.
            time.sleep(wait)
예제 #2
0
    def _transition(self, duration, color, brightness):
        """ Transition.

        :param duration: Time to transition.
        :param color: Transition to this color.
        :param brightness: Transition to this brightness.
        """
        # Calculate brightness steps.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness, brightness, BRIGHTNESS_STEPS)
            b_start = self.brightness
        # Calculate color steps.
        c_steps = 0
        if color is not None:
            c_steps = abs(
                util.rgb_to_hue(*self.color) - util.rgb_to_hue(*color))
            c_start = rgb_to_hsv(*self._color)
            c_end = rgb_to_hsv(*color)
        # Compute ideal step amount (at least one).
        total = max(c_steps + b_steps, 1)
        # Calculate wait.
        wait = self._wait(duration, total)
        # Scale down steps if no wait time.
        if wait == 0:
            total = self._scaled_steps(duration, total, total)
        # Perform transition.
        j = 0
        for i in range(total):
            # Brightness.
            if (b_steps > 0 and i % math.ceil(total / b_steps) == 0):
                j += 1
                self.brightness = util.transition(j, b_steps, b_start,
                                                  brightness)
            # Color.
            elif c_steps > 0:
                rgb = hsv_to_rgb(*util.transition3(i - j + 1, total -
                                                   b_steps, c_start, c_end))
                self.color = Color(*rgb)
            # Wait.
            time.sleep(wait)
예제 #3
0
    def color(self, color):
        """ Set group color.

        Color is set on a best-effort basis.

        :param color: RGB color tuple.
        """
        if color == RGB_WHITE:
            self.white()
            return
        self._color = color
        hue = util.rgb_to_hue(*color)
        cmd = [0x40, hue]
        self.send(cmd, select=True)
예제 #4
0
    def color(self, color):
        """ Set group color.

        Color is set on a best-effort basis.

        :param color: RGB color tuple.
        """
        if color == RGB_WHITE:
            self.white()
            return
        self._color = color
        hue = util.rgb_to_hue(*color)
        cmd = [0x40, hue]
        self.send(cmd, select=True)