コード例 #1
0
ファイル: gradient.py プロジェクト: raymiec/LedFx
    def _generate_bezier_curve(self, gradient_colors, gradient_length):

        # Check to see if we have a custom gradient, or a predefined one and
        # load the colors accordingly
        if isinstance(gradient_colors, str):
            gradient_name = gradient_colors.lower()
            gradient_colors = []
            if GRADIENTS.get(gradient_name):
                gradient_colors = GRADIENTS.get(gradient_name)
            elif COLORS.get(gradient_name):
                gradient_colors = [gradient_name]

        if not gradient_colors:
            gradient_colors = GRADIENTS.get('spectral')

        rgb_list = np.array(
            [COLORS[color.lower()] for color in gradient_colors]).T
        n_colors = len(rgb_list[0])

        t = np.linspace(0.0, 1.0, gradient_length)
        polynomial_array = np.array([
            self._bernstein_poly(i, n_colors - 1, t)
            for i in range(0, n_colors)
        ])
        gradient = np.array([
            np.dot(rgb_list[0], polynomial_array),
            np.dot(rgb_list[1], polynomial_array),
            np.dot(rgb_list[2], polynomial_array)
        ])

        _LOGGER.info(
            ('Generating new gradient curve for {}'.format(gradient_colors)))
        self._gradient_curve = gradient
コード例 #2
0
ファイル: gradient.py プロジェクト: Mattallmighty/LedFx-OLD
    def _generate_gradient_curve(self, gradient_colors, gradient_length,
                                 repeat):

        # Check to see if we have a custom gradient, or a predefined one and
        # load the colors accordingly
        if isinstance(gradient_colors, str):
            gradient_name = gradient_colors
            gradient_colors = []
            if GRADIENTS.get(gradient_name):
                gradient_colors = GRADIENTS.get(gradient_name).get("colors")
                #gradient_method = GRADIENTS.get(gradient_name).get("method", gradient_method)
            elif COLORS.get(gradient_name):
                gradient_colors = [gradient_name]

        if not gradient_colors:
            gradient_colors = GRADIENTS.get('spectral')

        self.rgb_list = np.array(
            [COLORS[color.lower()] for color in gradient_colors]).T
        n_colors = len(self.rgb_list[0])

        # if gradient_method == "bezier":
        #     t = np.linspace(0.0, 1.0, gradient_length)
        #     polynomial_array = np.array([self._bernstein_poly(i, n_colors-1, t) for i in range(0, n_colors)])
        #     polynomial_array = np.fliplr(polynomial_array)
        #     gradient = np.array([np.dot(self.rgb_list[0], polynomial_array),
        #                          np.dot(self.rgb_list[1], polynomial_array),
        #                          np.dot(self.rgb_list[2], polynomial_array)])
        #     _LOGGER.info(('Generating new gradient curve for {}'.format(gradient_colors)))
        #     self._gradient_curve = gradient

        # elif gradient_method == "cubic_ease":

        gradient = np.zeros((3, gradient_length))
        gradient_split = np.array_split(gradient, repeat, axis=1)
        for i in range(len(gradient_split)):
            segment_length = len(gradient_split[i][0])
            t = np.zeros(segment_length)
            ease_chunks = np.array_split(t, n_colors - 1)
            color_pairs = np.array([(self.rgb_list.T[i],
                                     self.rgb_list.T[i + 1])
                                    for i in range(n_colors - 1)])
            gradient_split[i] = np.hstack(
                self._color_ease(len(ease_chunks[i]), *color_pairs[i])
                for i in range(n_colors - 1))
        _LOGGER.info(
            ('Generating new gradient curve for {}'.format(gradient_colors)))
        self._gradient_curve = np.hstack(gradient_split)
コード例 #3
0
ファイル: gradient.py プロジェクト: willjschmitt/LedFx
    def _generate_bezier_curve(self, gradient_colors, gradient_length):

        gradient_method = "bezier"

        # Check to see if we have a custom gradient, or a predefined one and
        # load the colors accordingly
        if isinstance(gradient_colors, str):
            gradient_name = gradient_colors
            gradient_colors = []
            if GRADIENTS.get(gradient_name):
                gradient_colors = GRADIENTS.get(gradient_name).get("colors")
                gradient_method = GRADIENTS.get(gradient_name).get("method", "bezier")
            elif COLORS.get(gradient_name):
                gradient_colors = [gradient_name]

        if not gradient_colors:
            gradient_colors = GRADIENTS.get('spectral')

        self.rgb_list = np.array([COLORS[color.lower()] for color in gradient_colors]).T
        n_colors = len(self.rgb_list[0])

        if gradient_method == "bezier":
            t = np.linspace(0.0, 1.0, gradient_length)
            polynomial_array = np.array([self._bernstein_poly(i, n_colors-1, t) for i in range(0, n_colors)])
            gradient = np.array([np.dot(self.rgb_list[0], polynomial_array),
                                np.dot(self.rgb_list[1], polynomial_array),
                                np.dot(self.rgb_list[2], polynomial_array)])

            _LOGGER.info(('Generating new gradient curve for {}'.format(gradient_colors)))
            self._gradient_curve = gradient
        else:
            gradient = np.zeros((gradient_length, 3))
            for i in range(gradient_length):
                rgb_i = i % n_colors
                gradient[i] = (self.rgb_list[0][rgb_i], self.rgb_list[1][rgb_i], self.rgb_list[2][rgb_i])
            self._gradient_curve = gradient.T