コード例 #1
0
    def line(self, row1: int, col1: int, row2: int, col2: int,
             color: ColorType=None, alpha: float=1.0) -> 'Layer':
        """
        Draw a line between two points

        :param row1: Start row
        :param col1: Start column
        :param row2: End row
        :param col2: End column
        :param color: Color to draw with
        """
        rr, cc, aa = draw.line_aa(clamp(0, self.height, row1), clamp(0, self.width, col1),
                                  clamp(0, self.height, row2), clamp(0, self.width, col2))
        self._draw(rr, cc, color, aa)

        return self
コード例 #2
0
    def _ease(n):
        n = clamp(n, 0.0, 1.0)
        n = 2 * n
        if n < 1:
            return 0.5 * n**5

        n = n - 2
        return 0.5 * (n**5 + 2)
コード例 #3
0
ファイル: color.py プロジェクト: burnsed/uchroma
def rgb_to_int_tuple(arg: tuple) -> tuple:
    """
    Convert/sanitize a 3-tuple of ints or floats

    :param arg: Tuple of RGB values

    :return: Tuple of RGB ints
    """
    if len(arg) >= 3:

        return tuple([clamp(round(x), 0, 255) for x in arg[:3]])

    raise TypeError('Unable to convert %s (%s) to color' % (arg, type(arg[0])))
コード例 #4
0
ファイル: mouse.py プロジェクト: sj26/uchroma
    def set_idle_time(self, idle_time: int):
        """
        Sets the idle time in seconds. The device will enter powersave
        mode after the timeout expires.

        :param idle_time: Timeout in seconds. Must be between 60 and 900.

        :return: True if successful
        """
        idle_time = clamp(idle_time, 60, 900)
        arg = struct.pack('>H', idle_time)

        return self.run_command(UChromaMouse.Command.SET_IDLE_TIME, arg)
コード例 #5
0
ファイル: input_queue.py プロジェクト: quinndiggity/uchroma
 def percent_complete(self) -> float:
     """
     Percentage of elapsed time until this event expires
     """
     duration = self.expire_time - self.timestamp
     return clamp(self.time_remaining / duration, 0.0, 1.0)