Exemplo n.º 1
0
    def audio_data_updated(self, data):

        # Calculate the low, mids, and high indexes scaling based on the pixel count
        intensities = np.array([
            np.mean(data.melbank_lows()),
            np.mean(data.melbank_mids()),
            np.mean(data.melbank_highs())
        ])

        self.update_drop_frames()

        if intensities[0] - self.filtered_intensities[0] > self._config[
                "lows_sensitivity"]:
            self.new_drop(randint(0, self.pixel_count - 1),
                          COLORS.get(self._config['lows_colour']))
        if intensities[1] - self.filtered_intensities[1] > self._config[
                "mids_sensitivity"]:
            self.new_drop(randint(0, self.pixel_count - 1),
                          COLORS.get(self._config['mids_colour']))
        if intensities[2] - self.filtered_intensities[2] > self._config[
                "high_sensitivity"]:
            self.new_drop(randint(0, self.pixel_count - 1),
                          COLORS.get(self._config['high_colour']))

        self.filtered_intensities = self.intensity_filter.update(intensities)

        self.pixels = self.get_drops()
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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