Basis 1920x1080 mit Kachel 96 (Phase 0.5): Assets, Daten-ids, Engine, Theme und Pruefungen umgestellt; alte 32-px-Master im Archiv. Boden, Dach und Haus gezeichnet statt generiert (boden.py, dach.py) — FLUX-Kacheln hatten nach --flatten nur zwei Farben. Schrift neu in Zielaufloesung (font16.py, 12x16 entworfen, x2 exportiert, proportionaler Vorschub). Zwei Register: gemaltes Ortsbild mit Hotspots und Kachelgebiet mit gemalten Figuren, verbunden ueber einen ScreenManager. Die Schleife ist ohne Fenster geprueft (tools/probe_schleife.tscn). Dokumentation: darstellung.md (Regeln), stand.md (Uebergabe), Beweise unter art/prep/ (terrain-96, kacheltest, stadt-gemalt, schleife, stil-vergleich).
222 lines
7.9 KiB
Python
222 lines
7.9 KiB
Python
#!/usr/bin/env python3
|
|
"""dach.py - Dachsatz aus drei Teilen: First, Flaeche, Traufe.
|
|
|
|
Warum kein einzelnes Dach-Motiv: ein Rechteck aus einer Plankenkachel liest
|
|
sich als Holzfussboden. Ein Dach braucht **Kanten** — oben den First, unten die
|
|
Traufe mit Schatten. Erst die drei Teile zusammen ergeben ein Bauwerk, und die
|
|
Engine entscheidet je Kachel, welcher Teil sie ist (Nachbarschaft, wie bei den
|
|
Uebergaengen).
|
|
|
|
python3 art/tools/dach.py --out ../prep/terrain-96/gewaehlt
|
|
|
|
Erzeugt:
|
|
|
|
tile_dach_first_96px.png obere Kante eines Dachs, heller First
|
|
tile_dach_mitte_96px.png Plankenflaeche
|
|
tile_dach_traufe_96px.png untere Kante, dunkler Ueberstand
|
|
|
|
Alle drei sind horizontal kachelbar: die Plankenteilung wiederholt sich ueber
|
|
den Rand, und jedes Teil ist genau 96 px hoch.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import random
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
|
|
|
# Weltpalette, Brauntoene. Das Dach lag zuerst zwei Stufen zu dunkel — gegen
|
|
# die helle Fassade wirkte es wie Teerpappe. Eine Stufe heller, und der
|
|
# Kontrast stimmt, ohne dass das Dach heller wird als die Wand.
|
|
PLANKE = (0x6B, 0x57, 0x44)
|
|
PLANKE_H = (0x8C, 0x73, 0x55)
|
|
PLANKE_T = (0x4C, 0x40, 0x33)
|
|
FUGE = (0x3A, 0x2F, 0x27)
|
|
FIRST = (0x7C, 0x67, 0x4E)
|
|
SCHATTEN = (0x14, 0x10, 0x0D)
|
|
|
|
REIHE = 12 # Höhe einer Plankenreihe
|
|
|
|
|
|
def flaeche(w: int, h: int, rnd: random.Random, oben: int = 0,
|
|
ton=(0x6B, 0x57, 0x44), hell=(0x8C, 0x73, 0x55),
|
|
dunkel=(0x4C, 0x40, 0x33)) -> Image.Image:
|
|
"""Plankenfläche: Reihen mit Fuge, Bretter mit Trennungen."""
|
|
im = Image.new("RGB", (w, h), ton)
|
|
px = im.load()
|
|
y = oben
|
|
reihe = 0
|
|
while y < h:
|
|
reihen_ton = ton if reihe % 2 == 0 else dunkel
|
|
for x in range(w):
|
|
for dy in range(REIHE):
|
|
if y + dy < h:
|
|
px[x, y + dy] = reihen_ton
|
|
# Fuge am unteren Rand der Reihe
|
|
for x in range(w):
|
|
if y + REIHE < h:
|
|
px[x, y + REIHE] = FUGE
|
|
# Brett-Trennungen, je Reihe versetzt
|
|
versatz = (reihe * 23) % 34
|
|
for x in range(versatz, w, 34):
|
|
for dy in range(REIHE):
|
|
if y + dy < h:
|
|
px[x % w, y + dy] = dunkel
|
|
# Lichtkante oben an der Reihe
|
|
for x in range(w):
|
|
px[x, y] = hell if reihe % 2 == 0 else ton
|
|
y += REIHE + 1
|
|
reihe += 1
|
|
return im
|
|
|
|
|
|
def first(w: int = 96, h: int = 96) -> Image.Image:
|
|
"""Obere Kante: heller First mit dunkler Schattenlinie darunter."""
|
|
rnd = random.Random(1)
|
|
# Hangcharakter: am First liegt das Dach im Eigen-Schatten, zur Traufe hin
|
|
# wird es heller. Gleichmäßige Planken lesen als Fläche, nicht als Schräge.
|
|
im = flaeche(w, h, rnd, oben=10, ton=(0x4C, 0x40, 0x33),
|
|
hell=(0x6B, 0x57, 0x44), dunkel=(0x3A, 0x2F, 0x27))
|
|
px = im.load()
|
|
for x in range(w):
|
|
px[x, 0] = SCHATTEN # Abschluss nach oben
|
|
px[x, 1] = FIRST
|
|
for y in range(2, 7):
|
|
px[x, y] = FIRST if y < 5 else PLANKE_H
|
|
px[x, 7] = PLANKE_T # Schattenkante unter dem First
|
|
px[x, 8] = SCHATTEN
|
|
px[x, 9] = PLANKE_T
|
|
return im
|
|
|
|
|
|
def mitte(w: int = 96, h: int = 96) -> Image.Image:
|
|
return flaeche(w, h, random.Random(2), ton=(0x6B, 0x57, 0x44),
|
|
hell=(0x7C, 0x67, 0x4E), dunkel=(0x4C, 0x40, 0x33))
|
|
|
|
|
|
def traufe(w: int = 96, h: int = 96) -> Image.Image:
|
|
"""Untere Kante: Überstand, darunter die Schattenkante zum Boden."""
|
|
im = flaeche(w, h, random.Random(3), ton=(0x7C, 0x67, 0x4E),
|
|
hell=(0x8C, 0x73, 0x55), dunkel=(0x6B, 0x57, 0x44))
|
|
px = im.load()
|
|
for x in range(w):
|
|
for y in range(h - 14, h - 4):
|
|
px[x, y] = PLANKE_T
|
|
px[x, h - 4] = FUGE
|
|
for y in range(h - 3, h):
|
|
px[x, y] = SCHATTEN
|
|
return im
|
|
|
|
|
|
# ------------------------------------------------------------- Fassade ----
|
|
# Das Haus braucht eine Wand. In dieser Projektion steht der Betrachter südlich
|
|
# des Bauwerks: man sieht First, Dachschräge, Traufe — und darunter die
|
|
# Fassade mit Tür. Ohne sie ist das Dach eine Fläche auf dem Boden.
|
|
PUTZ = (0xB0, 0xA0, 0x82)
|
|
PUTZ_T = (0x92, 0x8A, 0x74)
|
|
BALKEN = (0x6B, 0x57, 0x44)
|
|
BALKEN_T = (0x4C, 0x40, 0x33)
|
|
MAUER = (0x5D, 0x5F, 0x54)
|
|
TUER = (0x4C, 0x40, 0x33)
|
|
BESCHLAG = (0xD8, 0xB4, 0x68)
|
|
|
|
|
|
def fassade(tuer: bool, w: int = 96, h: int = 96) -> Image.Image:
|
|
"""Fachwerk: Balken tragen die Fläche, der Putz füllt nur die Gefache.
|
|
|
|
Die erste Fassung war eine helle Putzfläche mit einem Fenster — damit war
|
|
sie die hellste Stelle im ganzen Bild und zog den Blick von den Figuren
|
|
weg. Balken lösen das ohne Farbwechsel: dieselbe Palette, weniger helle
|
|
Fläche.
|
|
"""
|
|
im = Image.new("RGB", (w, h), PUTZ)
|
|
px = im.load()
|
|
for y in range(h):
|
|
for x in range(w):
|
|
px[x, y] = PUTZ_T if (x * 31 + y * 17) % 97 < 6 else PUTZ
|
|
|
|
def balken(x0, y0, x1, y1):
|
|
for y in range(y0, y1 + 1):
|
|
for x in range(x0, x1 + 1):
|
|
if 0 <= x < w and 0 <= y < h:
|
|
px[x, y] = BALKEN
|
|
if 0 <= y1 + 1 < h:
|
|
for x in range(x0, min(x1 + 1, w)):
|
|
px[x, y1 + 1] = BALKEN_T
|
|
|
|
# Schatten unter der Traufe (kürzer und wärmer als in der ersten Fassung)
|
|
for y in range(8):
|
|
for x in range(w):
|
|
px[x, y] = BALKEN_T if y < 5 else SCHATTEN
|
|
balken(0, 8, w - 1, 13) # Rähm
|
|
balken(0, 84, w - 1, 88) # Schwelle
|
|
for x0 in (0, 45, 91): # Ständer
|
|
balken(x0, 8, x0 + 4, 88)
|
|
for y in range(18, 82, 14): # Riegel
|
|
if y > 60:
|
|
continue
|
|
balken(5, y, w - 6, y + 2)
|
|
for (x0, y0, x1, y1) in [(5, 24, 44, 60), (50, 24, 90, 60)]:
|
|
steps = x1 - x0
|
|
for i in range(steps):
|
|
yy = y0 + int((y1 - y0) * i / max(steps - 1, 1))
|
|
px[x0 + i, yy] = BALKEN
|
|
for y in range(h - 6, h):
|
|
for x in range(w):
|
|
px[x, y] = MAUER
|
|
for x in range(w):
|
|
px[x, h - 6] = BALKEN_T
|
|
|
|
if tuer:
|
|
x0, x1, y0 = 34, 62, 40
|
|
for x in range(x0 - 2, x1 + 2):
|
|
for y in range(y0 - 2, h):
|
|
px[x, y] = BALKEN
|
|
for x in range(x0, x1):
|
|
for y in range(y0, h):
|
|
px[x, y] = TUER
|
|
for x in range(x0 + 6, x1, 11):
|
|
for y in range(y0, h):
|
|
px[x, y] = BALKEN_T
|
|
for y in range(y0 + 12, y0 + 15):
|
|
for x in range(x0 - 2, x1 + 2):
|
|
px[x, y] = BALKEN_T
|
|
px[x1 - 7, y0 + 24] = BESCHLAG
|
|
px[x1 - 7, y0 + 25] = BESCHLAG
|
|
else:
|
|
x0, y0, breite, hoehe = 20, 22, 26, 30
|
|
for x in range(x0 - 2, x0 + breite + 2):
|
|
for y in range(y0 - 2, y0 + hoehe + 2):
|
|
px[x, y] = BALKEN
|
|
for x in range(x0, x0 + breite):
|
|
for y in range(y0, y0 + hoehe):
|
|
px[x, y] = SCHATTEN
|
|
for x in range(x0 + breite // 2, x0 + breite // 2 + 2):
|
|
for y in range(y0, y0 + hoehe):
|
|
px[x, y] = BALKEN
|
|
for y in range(y0 + hoehe // 2, y0 + hoehe // 2 + 2):
|
|
for x in range(x0, x0 + breite):
|
|
px[x, y] = BALKEN
|
|
return im
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
ap.add_argument("--out", type=Path, required=True)
|
|
a = ap.parse_args(argv)
|
|
a.out.mkdir(parents=True, exist_ok=True)
|
|
teile = [("first", first()), ("mitte", mitte()), ("traufe", traufe())]
|
|
for name, bild in teile:
|
|
ziel = a.out / f"tile_dach_{name}_96px.png"
|
|
bild.save(ziel)
|
|
print(f" {ziel.name} {bild.width}x{bild.height}")
|
|
for name, bild in [("wand", fassade(False)), ("tuer", fassade(True))]:
|
|
ziel = a.out / f"tile_haus_{name}_96px.png"
|
|
bild.save(ziel)
|
|
print(f" {ziel.name} {bild.width}x{bild.height}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|