"""Background tiles (real colours, transparent ground) from the mockup's PATTERNS.""" from svg_common import LEAF_PATH, MAPLE_LEAF_PATH, MockupRandom, num, svg_document, wrapped_copies def memphis_tile(pattern): """Squiggle, triangle, dot grid, zigzag, plus and square: the Memphis look.""" dots = "".join(f'' for column in range(4) for row in range(3)) body = ( f'' f'' f'' f'{dots}' f'' f'' f'') return 180, 180, body def leaves_tile(pattern): """Nine drifting leaves (plain and maple) placed by the mockup's seed.""" random = MockupRandom(11) colours = [pattern["p1"], pattern["p2"], pattern["p3"], pattern["p4"]] leaves = "" for index in range(9): x, y = random.next() * 200, random.next() * 200 angle, size = random.next() * 360, 0.7 + random.next() * 0.8 shape = MAPLE_LEAF_PATH if index % 2 else LEAF_PATH leaves += (f'') return 200, 200, wrapped_copies(leaves, 200, 200) def plank_tile(pattern): """Two vertical boards with seams, wavy grain and one knot. Opaque, so it replaces the plank fill.""" board_colours = ["#4e1c0d", "#5a2210"] seam_colour = "#2c0f06" width, height = 240, 220 body = "" for board in range(2): left = board * 120 body += f'' body += f'' for line in range(8): x = left + 8 + line * 14 stroke_width = 1.8 if line % 3 == 0 else 1 wobble = 5 if (line + board) % 2 else -4 body += (f'') body += (f'') body += f'' return width, height, body def _fern(pattern, x, y, angle, size): frond = (f'' f'') for step in range(1, 9): leaf_y, length = -step * 9, 16 - step * 1.4 frond += (f'') return frond + "" def ferns_tile(pattern): """Two ferns and two lily pads.""" body = _fern(pattern, 40, 170, -18, 1) + _fern(pattern, 170, 110, 24, 0.8) body += (f'' f'') return 220, 220, wrapped_copies(body, 220, 220) def stone_tile(pattern): """Stone block courses with two cracks and two shaded blocks.""" body = (f'' f'' f'' f'' f'' f'') return 160, 80, body def scan_tile(pattern): """A faint phosphor grid.""" return 28, 28, f'' TILE_MAKERS = {"memphis": memphis_tile, "leaves": leaves_tile, "grain": plank_tile, "ferns": ferns_tile, "stone": stone_tile, "scan": scan_tile} from tiles_more import MORE_TILE_MAKERS # noqa: E402 (second batch) TILE_MAKERS.update(MORE_TILE_MAKERS) # Rustic's tile is the whole plank floor, so it is drawn nearly opaque. OPACITY_OVERRIDES = {"grain": 0.92} def make_background_tile(pattern): """Return (svg_text, meta) for a pattern, or (None, None) when the mockup has no tile.""" maker = TILE_MAKERS.get(pattern["kind"]) if maker is None: return None, None width, height, body = maker(pattern) opacity = OPACITY_OVERRIDES.get(pattern["kind"], pattern.get("op", 1.0)) return svg_document(width, height, body), {"file": "background_tile.svg", "opacity": opacity, "scale": 1.0}