[WIP] recursive random table: tweak cell broder and fill logic

This commit is contained in:
Matthias Bisping 2023-01-18 13:42:38 +01:00
parent 4d181448b6
commit 384f0e5f28

View File

@ -441,17 +441,16 @@ class RecursiveRandomTable(RandomContentRectangle):
self.n_columns = max(self.width // 100, 1)
self.n_rows = max(self.height // 17, 1)
self.cell_size = (self.width // self.n_columns, self.height // self.n_rows)
logger.debug(f"RecursiveRandomTable({self.n_columns}, {self.n_rows}, {self.cell_size}) at {self}")
self.content = Image.new("RGB", (self.width, self.height), (255, 255, 255))
self.draw = ImageDraw.Draw(self.content)
self.content = Image.new("RGBA", (self.width, self.height), (255, 255, 255, 255))
self.background_color = tuple([random.randint(100, 200) for _ in range(4)])
self.cell_border_color = tuple(map(lambda x: int(x * 0.8), self.background_color[:3]))
def generate_random_table(self):
self.draw_single_cell_borders(self, 3)
cells = list(self.generate_cells_with_content())
self.content = paste_contents(self.content, cells)
# convert to RGBA
self.content = self.content.convert("RGBA")
assert self.content.mode == "RGBA"
# self.draw_cell_borders(cells)
def generate_cells_with_content(self):
for cell in self.generate_table():
@ -466,10 +465,12 @@ class RecursiveRandomTable(RandomContentRectangle):
for cell in cells:
self.draw_single_cell_borders(cell)
def draw_single_cell_borders(self, cell: ContentRectangle):
def draw_single_cell_borders(self, cell: ContentRectangle, width=1):
image = cell.content or Image.new("RGBA", (cell.width, cell.height), (255, 255, 255))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, cell.width, cell.height), fill=(126, 178, 231, 50), outline=(1, 1, 1), width=2)
draw.rectangle(
(0, 0, cell.width, cell.height), fill=self.background_color, outline=self.cell_border_color, width=width
)
cell.content = image
assert cell.content.mode == "RGBA"
return cell