コード例 #1
0
    def _transition(self, duration, brightness):
        """ Complete a transition.

        :param duration: Duration of transition.
        :param brightness: Transition to this brightness.
        """
        # Set initial value.
        b_start = self.brightness
        # Compute ideal step amount.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness, brightness,
                            self.command_set.brightness_steps)
        # Compute ideal step amount (at least one).
        # Calculate wait.
        wait = self._wait(duration, b_steps, b_steps)
        # Scale down steps if no wait time.
        if wait == 0:
            b_steps = self._scale_steps(duration, b_steps, b_steps)
        # Perform transition.
        for i in range(b_steps):
            # Brightness.
            if b_steps > 0:
                self.brightness = util.transition(i, b_steps, b_start,
                                                  brightness)
            time.sleep(wait)
コード例 #2
0
ファイル: white.py プロジェクト: smonkbr/python-limitlessled
    def _transition(self, duration, brightness, temperature):
        """ Complete a transition.

        :param duration: Duration of transition.
        :param brightness: Transition to this brightness.
        :param temperature: Transition to this temperature.
        """
        # Set initial value.
        b_start = self.brightness
        t_start = self.temperature
        # Compute ideal step amount.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness, brightness,
                            self.command_set.brightness_steps)
        t_steps = 0
        if temperature is not None:
            t_steps = steps(self.temperature, temperature,
                            self.command_set.temperature_steps)
        # Compute ideal step amount (at least one).
        total_steps = max(b_steps, t_steps, 1)
        total_commands = b_steps + t_steps
        # Calculate wait.
        wait = self._wait(duration, total_steps, total_commands)
        # Scale down steps if no wait time.
        if wait == 0:
            b_steps, t_steps = self._scale_steps(duration, total_commands,
                                                 b_steps, t_steps)
            total_steps = max(b_steps, t_steps, 1)
        # Perform transition.
        for i in range(total_steps):
            # Brightness.
            if b_steps > 0 and i % (total_steps / b_steps) == 0:
                self.brightness = util.transition(i, total_steps, b_start,
                                                  brightness)
            # Temperature.
            elif t_steps > 0:
                self.temperature = util.transition(i, total_steps, t_start,
                                                   temperature)
            # Wait.
            time.sleep(wait)
コード例 #3
0
ファイル: wrgb.py プロジェクト: smonkbr/python-limitlessled
    def _transition(self, duration, hue=None, brightness=None):
        """ Transition.

        :param duration: Time to transition.
        :param hue: Transition to this hue.
        :param brightness: Transition to this brightness.
        """
        # Calculate brightness steps.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness,
                            brightness, self.command_set.brightness_steps)
            b_start = self.brightness
        # Calculate hue steps.
        h_steps = 0
        if hue is not None:
            h_steps = steps(self.hue,
                            hue, self.command_set.hue_steps)
            h_start = self.hue
        # Compute ideal step amount (at least one).
        total_steps = max(b_steps, h_steps, 1)
        total_commands = b_steps + h_steps
        # Calculate wait.
        wait = self._wait(duration, total_steps, total_commands)
        # Scale down steps if no wait time.
        if wait == 0:
            b_steps, h_steps = self._scale_steps(duration, total_commands,
                                                 b_steps, h_steps)
            total_steps = max(b_steps, h_steps, 1)
        # Perform transition.
        for i in range(total_steps):
            # Brightness.
            if b_steps > 0 and i % math.ceil(total_steps/b_steps) == 0:
                self.brightness = util.transition(i, total_steps,
                                                  b_start, brightness)
            # Hue.
            if h_steps > 0 and i % math.ceil(total_steps/h_steps) == 0:
                self.hue = util.transition(i, total_steps,
                                           h_start, hue)
            # Wait.
            time.sleep(wait)
コード例 #4
0
    def _transition(self, duration, brightness, temperature):
        """ Complete a transition.

        :param duration: Duration of transition.
        :param brightness: Transition to this brightness.
        :param temperature: Transition to this temperature.
        """
        # Set initial value.
        b_start = self.brightness
        t_start = self.temperature
        # Compute ideal step amount.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness, brightness, STEPS)
        t_steps = 0
        if temperature is not None:
            t_steps = steps(self.temperature, temperature, STEPS)
        total = b_steps + t_steps
        # Compute wait.
        wait = self._wait(duration, total)
        # Scale down steps if no wait time.
        if wait == 0:
            b_steps = self._scaled_steps(duration, b_steps, total)
            t_steps = self._scaled_steps(duration, t_steps, total)
            total = b_steps + t_steps
        # Perform transition.
        j = 0
        for i in range(total):
            # Brightness.
            if b_steps > 0 and i % (total / b_steps) == 0:
                j += 1
                self.brightness = util.transition(j, b_steps, b_start,
                                                  brightness)
            # Temperature.
            elif t_steps > 0:
                self.temperature = util.transition(i - j + 1, t_steps, t_start,
                                                   temperature)
            # Wait.
            time.sleep(wait)
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
    def _transition(self,
                    duration,
                    brightness,
                    hue=None,
                    saturation=None,
                    temperature=None):
        """ Transition.

        :param duration: Time to transition.
        :param brightness: Transition to this brightness.
        :param hue: Transition to this hue.
        :param saturation: Transition to this saturation.
        :param temperature: Transition to this temperature.
        """
        # Calculate brightness steps.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness, brightness,
                            self.command_set.brightness_steps)
            b_start = self.brightness
        # Calculate hue steps.
        h_steps = 0
        if hue is not None:
            h_steps = steps(self.hue, hue, self.command_set.hue_steps)
            h_start = self.hue
        # Calculate saturation steps.
        s_steps = 0
        if saturation is not None:
            s_steps = steps(self.saturation, saturation,
                            self.command_set.saturation_steps)
            s_start = self.saturation
        # Calculate temperature steps.
        t_steps = 0
        if temperature is not None:
            t_steps = steps(self.temperature, temperature,
                            self.command_set.temperature_steps)
            t_start = self.temperature
        # Compute ideal step amount (at least one).
        total = max(b_steps + h_steps + s_steps + t_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.
        b_iteration = h_iteration = s_iteration = t_iteration = 0
        for i in range(total):
            # Brightness.
            if b_steps > 0 and i % math.ceil(total / b_steps) == 0:
                b_iteration += 1
                self.brightness = util.transition(b_iteration, b_steps,
                                                  b_start, brightness)
            # Hue.
            if h_steps > 0 and i % math.ceil(total / h_steps) == 0:
                h_iteration += 1
                self.hue = util.transition(h_iteration, h_steps, h_start, hue)
            # Saturation.
            if s_steps > 0 and i % math.ceil(total / s_steps) == 0:
                s_iteration += 1
                self.saturation = util.transition(s_iteration, s_steps,
                                                  s_start, saturation)
            # Temperature.
            if t_steps > 0 and i % math.ceil(total / t_steps) == 0:
                t_iteration += 1
                self.temperature = util.transition(t_iteration, t_steps,
                                                   t_start, temperature)

            # Wait.
            time.sleep(wait)
コード例 #8
0
 def test_transition(self):
     self.assertEqual(util.transition(0, 100, 0, 10), 0.0)
     self.assertEqual(util.transition(1, 100, 0, 10), 0.1)
     self.assertEqual(util.transition(10, 100, 0, 10), 1.0)
     self.assertEqual(util.transition(100, 100, 0, 10), 10.0)