Exemplo n.º 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
Exemplo n.º 2
0
                return {(1, 1): [two, three], (5, 5): [one, four]}[(i, j)]

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

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

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

            with mock.patch.object(canvas, "surrounding_colors", surrounding_colors):
                with mock.patch.object(ThemeColor, "average", average):
                    canvas.blur()

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

    describe "points for tile":
        it "gets the points in the correct order":
            # fmt: off
            points = [
                (0, 13,  1), (1, 13,  2), (2, 13,  3), (3, 13,  4), (4, 13,  5), (5, 13,  6), # noqa
                (0, 12,  7), (1, 12,  8), (2, 12,  9), (3, 12, 10), (4, 12, 11), (5, 12, 12), # noqa
                (0, 11, 13), (1, 11, 14), (2, 11, 15), (3, 11, 16), (4, 11, 17), (5, 11, 18), # noqa
                (0, 10, 19), (1, 10, 20), (2, 10, 21), (3, 10, 22), (4, 10, 23), (5, 10, 24), # noqa
                (0,  9, 25), (1,  9, 26), (2,  9, 27), (3,  9, 28), (4,  9, 29), (5,  9, 30), # noqa
                (0,  8, 31), (1,  8, 32), (2,  8, 33), (3,  8, 34), (4,  8, 35), (5,  8, 36)  # noqa
            ]
            # fmt: on