Пример #1
0
    def apply_theme(self, theme, return_canvas=False, canvas=None):
        """
        If a canvas is not supplied then we create a new canvas with random points
        around where each tile is. We then shuffle those points and blur them
        a little.

        We then fill in the gaps between the points.

        Then we blur the filled in points and create the 64 hsbk values for each
        tile.

        We return the list of ``[<64 hsbks>, <64 hsbks>, ...]``.

        If ``return_canvas`` is True then we return a tuple of ``(tiles, canvas)``
        """
        if canvas is None:
            canvas = Canvas()
            theme = theme.shuffled()
            theme.ensure_color()

            for (left_x, top_y), (w, h) in self.coords_and_sizes:
                canvas.add_points_for_tile(left_x, top_y, w, h, theme)
            canvas.shuffle_points()
            canvas.blur_by_distance()

        colors = TileColors()
        tile_canvas = Canvas()

        for (left_x, top_y), (tile_width,
                              tile_height) in self.coords_and_sizes:
            if self.just_points:
                colors.add_tile(
                    canvas.points_for_tile(left_x, top_y, tile_width,
                                           tile_height))
            else:
                tile_canvas.fill_in_points(canvas, left_x, top_y, tile_width,
                                           tile_height)

        if not self.just_points:
            if self.post_blur:
                tile_canvas.blur()

            self.add_tiles_from_canvas(colors, tile_canvas)

        if return_canvas:
            return colors.tiles, canvas

        return colors.tiles
Пример #2
0
            avg1 = ThemeColor(20, 1, 1, 3400)
            avg2 = ThemeColor(30, 1, 1, 3400)

            canvas = Canvas()
            canvas[(1, 1)] = red
            canvas[(5, 5)] = green

            def closest_points(i, j, consider):
                assert consider == 8
                return {(1, 1): distances1, (5, 5): distances2}[(i, j)]

            closest_points = mock.Mock(name="closest_points", side_effect=closest_points)

            def colorweighting(distances):
                return {distances1: [two, three], distances2: [one, four]}[distances]

            colorweighting = mock.Mock(name="colorweighting", side_effect=colorweighting)

            def average(colors):
                return {(two, three): avg1, (one, four): avg2}[tuple(colors)]

            average = mock.Mock(name="average", side_effect=average)

            with mock.patch.object(canvas, "closest_points", closest_points):
                with mock.patch.object(ThemeColor, "average", average):
                    with mock.patch("photons_themes.canvas.color_weighting", colorweighting):
                        canvas.blur_by_distance()

            assert sorted(canvas) == sorted([((1, 1), avg1), ((5, 5), avg2)])