Beispiel #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
Beispiel #2
0
                if point != (None, None):
                    canvas[point] = ThemeColor(i, 0, 0, 3500)

            # fmt: off
            expected = [
                (1, 8, 5.326),  (2, 8, 8.777),  (3, 8, 8.423),  (4, 8, 4.200),  (5, 8, 7.984),  (6, 8, 12.808),
                (1, 7, 17.341), (2, 7, 20.664), (3, 7, 17.266), (4, 7, 17.620), (5, 7, 18.132), (6, 7, 20.523),
                (1, 6, 22.856), (2, 6, 23.000), (3, 6, 23.334), (4, 6, 22.877), (5, 6, 26.653), (6, 6, 24.327),
                (1, 5, 26.144), (2, 5, 27.335), (3, 5, 26.254), (4, 5, 29.186), (5, 5, 29.988), (6, 5, 34.000),
                (1, 4, 31.763), (2, 4, 34.610), (3, 4, 33.489), (4, 4, 34.754), (5, 4, 40.807), (6, 4, 41.701),
                (1, 3, 45.014), (2, 3, 42.125), (3, 3, 42.641), (4, 3, 48.482), (5, 3, 49.431), (6, 3, 47.314)
            ]
            # fmt: on

            new_canvas = Canvas()
            new_canvas.fill_in_points(canvas, 1, 8, 6, 6)

            assert len(new_canvas) == len(expected)
            for x, y, hue in expected:
                assert "{:.3f}".format(new_canvas[(x, y)].hue) == "{:.3f}".format(hue)

    describe "getting closest points":
        it "gets the closest points":
            canvas = Canvas()

            _ = None
            # fmt: off
            points = [
                (0, 9), (1, 9), (_, _), (3, 9), (4, 9), (5, 9), (6, 9),
                (0, 8), (_, _), (_, _), (_, _), (_, _), (_, _), (_, _),
                (_, _), (_, _), (2, 7), (_, _), (_, _), (_, _), (6, 7),