How to use the ledfx.color.GRADIENTS.get function in LedFx

To help you get started, weโ€™ve selected a few LedFx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ahodges9 / LedFx / ledfx / effects / gradient.py View on Github external
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)])
github ahodges9 / LedFx / ledfx / effects / gradient.py View on Github external
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):
github ahodges9 / LedFx / ledfx / effects / gradient.py View on Github external
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),