예제 #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
            theme = Theme()
            theme.add_hsbk(0, 0, 1, 3500)
            theme.add_hsbk(100, 1, 0, 3400)
            theme.add_hsbk(320, 1, 1, 5900)
            return theme

        it "moves the points around", theme:
            canvas = Canvas()
            canvas.add_points_for_tile(-2, 0, 8, 8, theme)
            for (i, j), color in canvas:
                assert not canvas.has_neighbour(i, j)
                assert color in theme

            old_points = sorted(point for point, _ in canvas)

            canvas.shuffle_points()
            new_points = sorted(point for point, _ in canvas)

            assert new_points != old_points
            assert any(canvas.has_neighbour(i, j) for (i, j), _ in canvas)
            for (i, j), color in canvas:
                assert color in theme

    describe "blur":
        it "averages all the points with the surrounding colors":
            one = ThemeColor(1, 0, 1, 3500)
            two = ThemeColor(2, 0, 1, 3500)
            three = ThemeColor(3, 0, 1, 3500)
            four = ThemeColor(4, 0, 1, 3500)

            red = ThemeColor(0, 1, 1, 3500)