79 lines
3.8 KiB
Python
79 lines
3.8 KiB
Python
|
|
"""Second batch of background tiles (real colours, transparent ground) from the mockup's PATTERNS."""
|
||
|
|
|
||
|
|
from svg_common import LEAF_PATH, MockupRandom, num, wrapped_copies
|
||
|
|
|
||
|
|
|
||
|
|
def rain_tile(pattern):
|
||
|
|
"""Short slanted rain streaks."""
|
||
|
|
random = MockupRandom(3)
|
||
|
|
streaks = ""
|
||
|
|
for _ in range(18):
|
||
|
|
x, y, length = random.next() * 120, random.next() * 160, 8 + random.next() * 14
|
||
|
|
opacity = 0.25 + random.next() * 0.4
|
||
|
|
streaks += (f'<path d="M{num(x)} {num(y)} l-3 {num(length)}" stroke="{pattern["p1"]}" '
|
||
|
|
f'stroke-width="1" opacity="{num(opacity)}"/>')
|
||
|
|
return 120, 160, wrapped_copies(streaks, 120, 160)
|
||
|
|
|
||
|
|
|
||
|
|
def contour_tile(pattern):
|
||
|
|
"""Five nested wavy rings, like height lines on a map."""
|
||
|
|
rings = ""
|
||
|
|
for ring in range(1, 6):
|
||
|
|
size = ring * 15
|
||
|
|
rings += (f'<path d="M{num(100 - size)} 100 C{num(100 - size)} {num(100 - size * 1.1)} '
|
||
|
|
f'{num(100 + size * 0.7)} {num(100 - size)} {num(100 + size)} {num(100 - size * 0.2)} '
|
||
|
|
f'S{num(100 + size * 0.4)} {num(100 + size * 1.1)} {num(100 - size * 0.3)} {num(100 + size * 0.9)} '
|
||
|
|
f'S{num(100 - size)} {num(100 + size * 0.3)} {num(100 - size)} 100Z" fill="none" '
|
||
|
|
f'stroke="{pattern["p1"]}" stroke-width="1.2" opacity="{num(0.7 - ring * 0.08)}"/>')
|
||
|
|
return 200, 200, rings
|
||
|
|
|
||
|
|
|
||
|
|
def halftone_tile(pattern):
|
||
|
|
"""One halftone dot."""
|
||
|
|
return 10, 10, f'<circle cx="5" cy="5" r="1.9" fill="{pattern["p1"]}"/>'
|
||
|
|
|
||
|
|
|
||
|
|
def gears_tile(pattern):
|
||
|
|
"""Three gear outlines: a dashed thick ring for the teeth, a rim and a hub."""
|
||
|
|
def gear(x, y, radius):
|
||
|
|
return (f'<circle cx="{x}" cy="{y}" r="{radius}" fill="none" stroke="{pattern["p1"]}" '
|
||
|
|
f'stroke-width="{num(radius * 0.32)}" stroke-dasharray="{num(radius * 0.35)} {num(radius * 0.35)}"/>'
|
||
|
|
f'<circle cx="{x}" cy="{y}" r="{num(radius * 0.78)}" fill="none" stroke="{pattern["p1"]}" stroke-width="2"/>'
|
||
|
|
f'<circle cx="{x}" cy="{y}" r="{num(radius * 0.22)}" fill="none" stroke="{pattern["p1"]}" stroke-width="2"/>')
|
||
|
|
return 220, 220, gear(60, 60, 34) + gear(118, 104, 22) + gear(180, 180, 28)
|
||
|
|
|
||
|
|
|
||
|
|
def starfield_tile(pattern):
|
||
|
|
"""Thirty stars and a faint hex-grid trace."""
|
||
|
|
random = MockupRandom(5)
|
||
|
|
stars = ""
|
||
|
|
for _ in range(30):
|
||
|
|
x, y = random.next() * 180, random.next() * 180
|
||
|
|
radius = 0.6 if random.next() < 0.85 else 1.3
|
||
|
|
opacity = 0.35 + random.next() * 0.6
|
||
|
|
stars += f'<circle cx="{num(x)}" cy="{num(y)}" r="{radius}" fill="{pattern["p1"]}" opacity="{num(opacity)}"/>'
|
||
|
|
hexes = (f'<path d="M0 26 l15 -26 h30 l15 26 l-15 26 h-30z M60 26 h60 M90 52 l15 26 h30 l15 -26 M150 26 h30" '
|
||
|
|
f'fill="none" stroke="{pattern["p2"]}" stroke-width=".7" opacity=".35" transform="translate(0 50)"/>')
|
||
|
|
return 180, 180, wrapped_copies(stars, 180, 180) + hexes
|
||
|
|
|
||
|
|
|
||
|
|
def sprigs_tile(pattern):
|
||
|
|
"""Pressed flowers and leaves."""
|
||
|
|
random = MockupRandom(9)
|
||
|
|
sprigs = ""
|
||
|
|
for index in range(6):
|
||
|
|
x, y = random.next() * 200, random.next() * 200
|
||
|
|
if index % 2:
|
||
|
|
petals = "".join(f'<ellipse rx="3" ry="6" transform="rotate({angle}) translate(0 -6)"/>'
|
||
|
|
for angle in (0, 72, 144, 216, 288))
|
||
|
|
sprigs += (f'<g transform="translate({num(x)} {num(y)})" fill="{pattern["p1"]}" opacity=".45">{petals}'
|
||
|
|
f'<circle r="2.5" fill="{pattern["p2"]}"/></g>')
|
||
|
|
else:
|
||
|
|
sprigs += (f'<path d="{LEAF_PATH}" transform="translate({num(x)} {num(y)}) rotate({num(random.next() * 360)}) '
|
||
|
|
f'scale(.8)" fill="{pattern["p3"]}" opacity=".45"/>')
|
||
|
|
return 200, 200, wrapped_copies(sprigs, 200, 200)
|
||
|
|
|
||
|
|
|
||
|
|
MORE_TILE_MAKERS = {"rain": rain_tile, "contour": contour_tile, "halftone": halftone_tile,
|
||
|
|
"gears": gears_tile, "starfield": starfield_tile, "sprigs": sprigs_tile}
|