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
want = [ [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 2, 0, 2, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [0, 0, 3, 0, 0] ] # fmt: on def get_color(x, y): return ThemeColor(want[y][x], 1, 1, 3500) canvas = Canvas() canvas.set_all_points_for_tile(10, 2, 5, 6, get_color) tile = canvas.points_for_tile(10, 2, 5, 6) hues = [p.hue for p in tile] # fmt: off expected = [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 3, 0, 0 ] # fmt: on assert hues == expected