220 lines
9.1 KiB
Python
220 lines
9.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Изометрические SVG-рендеры комнат дома Барнева (v2).
|
|
|
|
Данные: ops/home/rooms/*.md + ops/home/plans/HOUSE-DIMENSIONS.md
|
|
Выход: ops/home/renders/<room>.svg
|
|
"""
|
|
import math
|
|
import os
|
|
|
|
SC = 62.0
|
|
COS30 = math.cos(math.radians(30))
|
|
SIN30 = math.sin(math.radians(30))
|
|
WALL_H = 2.7
|
|
WALL_T = 0.14
|
|
|
|
BG_TOP = "#141b22"
|
|
BG_BOT = "#0d1216"
|
|
FLOOR_A = "#2b3340"
|
|
FLOOR_B = "#27303c"
|
|
WALL_TOP = "#4a5563"
|
|
WALL_OUT = "#333e4a"
|
|
ACCENT = "#6ab0f3"
|
|
LAMP = "#ffd9a0"
|
|
|
|
# палитра мебели
|
|
WOOD = "#6b5643"
|
|
WOOD_D = "#57452f"
|
|
TEXTILE = "#4a5c72"
|
|
WHITE = "#d6dde6"
|
|
DARK = "#2e3946"
|
|
METAL = "#8a99a8"
|
|
GREEN = "#4d7a5f"
|
|
|
|
|
|
def iso(x, y, z=0.0):
|
|
return ((x - y) * COS30 * SC, (x + y) * SIN30 * SC - z * SC)
|
|
|
|
|
|
def shade(c, f):
|
|
c = c.lstrip("#")
|
|
r, g, b = (int(c[i:i + 2], 16) for i in (0, 2, 4))
|
|
return "#%02x%02x%02x" % (max(0, min(255, int(r * f))),
|
|
max(0, min(255, int(g * f))),
|
|
max(0, min(255, int(b * f))))
|
|
|
|
|
|
def poly(pts, fill, stroke="none", sw=0.5, op=1.0):
|
|
p = " ".join("%.1f,%.1f" % q for q in pts)
|
|
o = "" if op >= 1 else ' opacity="%.2f"' % op
|
|
return '<polygon points="%s" fill="%s" stroke="%s" stroke-width="%.1f"%s/>' % (p, fill, stroke, sw, o)
|
|
|
|
|
|
def box(x, y, w, d, h, color, z=0.0, stroke="#0b1116", sw=0.5):
|
|
x2, y2, z2 = x + w, y + d, z + h
|
|
top = [iso(x, y, z2), iso(x2, y, z2), iso(x2, y2, z2), iso(x, y2, z2)]
|
|
left = [iso(x, y2, z), iso(x2, y2, z), iso(x2, y2, z2), iso(x, y2, z2)]
|
|
right = [iso(x2, y, z), iso(x2, y2, z), iso(x2, y2, z2), iso(x2, y, z2)]
|
|
return (poly(left, shade(color, 0.66), stroke, sw) +
|
|
poly(right, shade(color, 0.84), stroke, sw) +
|
|
poly(top, shade(color, 1.06), stroke, sw))
|
|
|
|
|
|
def floor(w, d):
|
|
out = [poly([iso(0, 0), iso(w, 0), iso(w, d), iso(0, d)], FLOOR_A, "#1b232c", 1.0)]
|
|
# доски пола
|
|
step = 0.42
|
|
i = 0
|
|
y = 0.0
|
|
while y < d:
|
|
yy = min(y + step, d)
|
|
out.append(poly([iso(0, y), iso(w, y), iso(w, yy), iso(0, yy)],
|
|
FLOOR_B if i % 2 == 0 else FLOOR_A, "none", 0, 1.0))
|
|
y = yy
|
|
i += 1
|
|
return "".join(out)
|
|
|
|
|
|
def walls(w, d):
|
|
"""Задние стены с толщиной: по y=0 (правая) и по x=0 (левая)."""
|
|
out = []
|
|
# стена вдоль x = 0 (левая грань)
|
|
out.append(box(0, 0, WALL_T, d + WALL_T, WALL_H, WALL_OUT, sw=0.6))
|
|
# стена вдоль y = 0 (правая грань)
|
|
out.append(box(0, 0, w + WALL_T, WALL_T, WALL_H, shade(WALL_OUT, 1.12), sw=0.6))
|
|
return "".join(out)
|
|
|
|
|
|
def ceiling_lamp(w, d):
|
|
"""Потолочный светильник + мягкое пятно света на полу."""
|
|
cx, cy, h = w * 0.5, d * 0.45, WALL_H - 0.12
|
|
px, py = iso(cx, cy, h)
|
|
fx, fy = iso(cx, cy, 0)
|
|
return ('<ellipse cx="%.1f" cy="%.1f" rx="%.1f" ry="%.1f" fill="url(#spot)" opacity="0.55"/>'
|
|
'<circle cx="%.1f" cy="%.1f" r="9" fill="%s" opacity="0.95"/>'
|
|
'<circle cx="%.1f" cy="%.1f" r="20" fill="url(#glow)" opacity="0.75"/>'
|
|
% (fx, fy, 1.35 * SC * COS30, 1.35 * SC * SIN30,
|
|
px, py, LAMP, px, py))
|
|
|
|
|
|
def defs():
|
|
return ('<defs>'
|
|
'<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">'
|
|
'<stop offset="0%%" stop-color="%s"/><stop offset="100%%" stop-color="%s"/>'
|
|
'</linearGradient>'
|
|
'<radialGradient id="spot"><stop offset="0%%" stop-color="%s" stop-opacity="0.30"/>'
|
|
'<stop offset="100%%" stop-color="%s" stop-opacity="0"/></radialGradient>'
|
|
'<radialGradient id="glow"><stop offset="0%%" stop-color="%s" stop-opacity="0.55"/>'
|
|
'<stop offset="100%%" stop-color="%s" stop-opacity="0"/></radialGradient>'
|
|
'</defs>' % (BG_TOP, BG_BOT, LAMP, LAMP, LAMP, LAMP))
|
|
|
|
|
|
def render(name, w, d, area, items, note=""):
|
|
pts = [iso(0, 0), iso(w, 0), iso(w, d), iso(0, d),
|
|
iso(0, 0, WALL_H), iso(w, 0, WALL_H), iso(0, d, WALL_H), iso(w, d, WALL_H)]
|
|
xs = [p[0] for p in pts]
|
|
ys = [p[1] for p in pts]
|
|
pad_x, pad_top = 70, 70
|
|
pad_bot = 210
|
|
minx = min(xs) - pad_x
|
|
miny = min(ys) - pad_top
|
|
W = (max(xs) - min(xs)) + 2 * pad_x
|
|
H = (max(ys) - min(ys)) + pad_top + pad_bot
|
|
|
|
body = [floor(w, d)]
|
|
body.append(walls(w, d))
|
|
for it in sorted(items, key=lambda i: (i[1] + i[2], i[6] if len(i) > 6 else 0)):
|
|
t, x, y, iw, idd, ih, col = it[:7]
|
|
body.append(box(x, y, iw, idd, ih, col))
|
|
body.append(ceiling_lamp(w, d))
|
|
|
|
tx, ty = minx + 34, miny + H - 96
|
|
return ('<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" '
|
|
'viewBox="%.1f %.1f %.1f %.1f">%s'
|
|
'<rect x="%.1f" y="%.1f" width="%.1f" height="%.1f" fill="url(#bg)"/>%s'
|
|
'<text x="%.1f" y="%.1f" fill="#e8eef4" font-family="Inter,system-ui,sans-serif" '
|
|
'font-size="30" font-weight="700">%s</text>'
|
|
'<text x="%.1f" y="%.1f" fill="#8ba0b5" font-family="Inter,system-ui,sans-serif" '
|
|
'font-size="17">%s м²%s</text></svg>') % (
|
|
int(W), int(H), minx, miny, W, H, defs(),
|
|
minx, miny, W, H, "".join(body),
|
|
tx, ty, name, tx, ty + 28, area, (" · " + note) if note else "")
|
|
|
|
|
|
ROOMS = {
|
|
"bedroom": ("Спальня", 3.3, 3.5, "11.45", "трек · 2 бра · гардеробная", [
|
|
("Кровать", 0.75, 1.0, 1.6, 2.0, 0.5, TEXTILE),
|
|
("Изголовье", 0.75, 0.95, 1.6, 0.14, 0.95, WOOD_D),
|
|
("Тумба", 0.42, 0.95, 0.33, 0.42, 0.48, WOOD),
|
|
("Тумба", 2.36, 0.95, 0.33, 0.42, 0.48, WOOD),
|
|
("Гардероб", 2.45, 0.35, 0.7, 0.85, 2.15, WOOD_D),
|
|
("Стол", 0.28, 2.55, 1.25, 0.42, 0.74, WOOD),
|
|
("ТВ", 2.62, 0.22, 0.55, 0.1, 0.68, DARK),
|
|
]),
|
|
"kitchen-living": ("Кухня-гостиная", 6.0, 4.6, "27.65", "2 трека · бра · подсветка", [
|
|
("Кухня", 0.15, 0.16, 3.0, 0.62, 0.9, WOOD),
|
|
("Столешница", 0.15, 0.16, 3.0, 0.62, 0.06, METAL),
|
|
("Холодильник", 2.95, 0.16, 0.62, 0.62, 1.9, WHITE),
|
|
("Вытяжка", 1.35, 0.2, 0.7, 0.45, 0.4, METAL),
|
|
("Стол", 3.5, 2.1, 1.5, 0.95, 0.74, WOOD),
|
|
("Диван", 0.45, 3.35, 2.3, 0.95, 0.72, TEXTILE),
|
|
("ТВ 75", 4.75, 2.6, 1.55, 0.1, 0.92, DARK),
|
|
("Стеллаж", 5.3, 0.3, 0.55, 2.1, 2.0, WOOD_D),
|
|
("Станция", 3.1, 3.7, 0.32, 0.32, 0.26, DARK),
|
|
]),
|
|
"office": ("Кабинет", 3.2, 3.5, "11.14", "трек · 2 бра · подсветка", [
|
|
("Стол", 0.25, 1.15, 1.75, 0.7, 0.74, WOOD),
|
|
("Монитор 1", 0.5, 1.3, 0.55, 0.08, 0.42, DARK),
|
|
("Монитор 2", 1.15, 1.3, 0.55, 0.08, 0.42, DARK),
|
|
("Кресло", 0.95, 2.15, 0.6, 0.6, 0.95, TEXTILE),
|
|
("ТВ TCL", 2.62, 0.24, 0.48, 0.1, 0.64, DARK),
|
|
("PS5", 2.55, 0.95, 0.3, 0.34, 0.38, WHITE),
|
|
("Кондиционер", 0.2, 0.2, 0.9, 0.24, 0.3, WHITE),
|
|
("Шкаф", 2.42, 0.3, 0.6, 0.75, 2.1, WOOD_D),
|
|
]),
|
|
"bathroom": ("Санузел", 2.5, 2.5, "6.29", "LED-профиль", [
|
|
("Ванна", 0.14, 0.14, 1.7, 0.78, 0.52, WHITE),
|
|
("Душ-поддон", 1.94, 0.14, 0.42, 0.9, 0.06, METAL),
|
|
("Унитаз", 0.45, 1.85, 0.4, 0.52, 0.4, WHITE),
|
|
("Раковина", 1.5, 1.6, 0.7, 0.42, 0.82, WHITE),
|
|
("Шкаф-зеркало", 1.55, 2.22, 0.7, 0.2, 0.85, DARK),
|
|
("Стиралка", 1.05, 0.2, 0.6, 0.6, 0.85, WHITE),
|
|
]),
|
|
"corridor": ("Коридор + тамбур", 1.6, 5.2, "6.32", "трек · бра · прихожая", [
|
|
("Шкаф", 0.14, 0.3, 0.55, 1.6, 2.1, WOOD_D),
|
|
("Скамья", 0.14, 2.15, 0.42, 0.9, 0.42, WOOD),
|
|
("Зеркало", 1.18, 1.2, 0.1, 0.9, 1.6, METAL),
|
|
("Тумба", 1.1, 3.5, 0.34, 0.6, 0.78, WOOD),
|
|
("Коврик", 0.35, 4.1, 0.9, 0.6, 0.02, GREEN),
|
|
]),
|
|
"danina": ("Данина (детская)", 3.7, 3.9, "14.34", "трек · антресоль", [
|
|
("Кровать", 0.35, 0.4, 1.5, 2.0, 0.5, TEXTILE),
|
|
("Стол", 2.2, 0.35, 1.2, 0.52, 0.74, WOOD),
|
|
("Диван", 0.35, 3.0, 1.95, 0.85, 0.72, TEXTILE),
|
|
("ТВ TCL", 2.55, 2.35, 0.9, 0.1, 0.6, DARK),
|
|
("Антресоль", 2.35, 1.35, 1.25, 1.35, 0.14, WOOD_D),
|
|
("Лестница", 2.05, 1.45, 0.28, 1.15, 0.92, METAL),
|
|
("Шкаф", 3.28, 0.3, 0.34, 1.0, 2.0, WOOD_D),
|
|
]),
|
|
"laundry": ("Прачечная", 1.8, 1.9, "1.30", "кладовая", [
|
|
("Стиралка", 0.16, 0.16, 0.6, 0.6, 0.85, WHITE),
|
|
("Сушилка", 0.82, 0.16, 0.6, 0.6, 0.85, WHITE),
|
|
("Полка", 0.16, 1.3, 1.45, 0.36, 1.8, WOOD_D),
|
|
]),
|
|
}
|
|
|
|
|
|
def main():
|
|
out = "/root/buryan-infra/ops/home/renders"
|
|
os.makedirs(out, exist_ok=True)
|
|
for key, (name, w, d, area, note, items) in ROOMS.items():
|
|
svg = render(name, w, d, area, items, note)
|
|
open(os.path.join(out, key + ".svg"), "w", encoding="utf-8").write(svg)
|
|
print(" %-16s %-22s %d КБ" % (key, name, len(svg) // 1024))
|
|
print("готово:", len(ROOMS), "файлов в", out)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|