"""店の形(JSON)を上から見た図にする。使い方: python3 render_layout.py layout_v0.json out.png""" import json import sys import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from matplotlib.patches import Rectangle, Circle, Polygon, FancyArrowPatch plt.rcParams["font.family"] = "Noto Sans CJK JP" INK = "#1f2328" MUTED = "#8a9099" BACK = "#eceef1" SEAT = "#ffffff" ROBOT = "#e8590c" DRINK = "#1c7ed6" DISH = "#2f9e44" def rect(ax, r, fc, ec=INK, lw=1.2, hatch=None, z=1): x0, y0, x1, y1 = r ax.add_patch(Rectangle((x0, y0), x1 - x0, y1 - y0, fc=fc, ec=ec, lw=lw, hatch=hatch, zorder=z)) def label(ax, x, y, text, size=9, color=INK, z=5, **kw): ax.text(x, y, text, ha="center", va="center", fontsize=size, color=color, zorder=z, **kw) def draw_table(ax, t): typ, x, y = t["type"], t["x"], t["y"] if typ == "t4": # 4人掛けの角テーブル(1.2m角) rect(ax, (x - 0.6, y - 0.6, x + 0.6, y + 0.6), SEAT, z=3) label(ax, x, y, "4", 11) elif typ == "r4": # 丸テーブル(直径1.1m) ax.add_patch(Circle((x, y), 0.55, fc=SEAT, ec=INK, lw=1.2, zorder=3)) label(ax, x, y, "4", 11) elif typ == "long6": # 背中合わせのスツール席(6人) rect(ax, (x - 1.6, y - 0.35, x + 1.6, y + 0.35), SEAT, z=3) for dx in (-1.0, 0.0, 1.0): for dy in (-0.75, 0.75): ax.add_patch(Circle((x + dx, y + dy), 0.22, fc=SEAT, ec=INK, lw=1, zorder=3)) label(ax, x, y, "6", 10) elif typ == "booth6L": # 壁ぞいのL字ボックス w, h = t["w"], t["h"] pts = [(x, y), (x + w, y), (x + w, y + h * 0.45), (x + w * 0.55, y + h * 0.45), (x + w * 0.55, y + h), (x, y + h)] ly = y + h * 0.4 if t.get("flip"): # 広い側を上にする pts = [(px, 2 * y + h - py) for px, py in pts] ly = y + h * 0.6 lx = x + w * 0.3 if t.get("mirror"): # 右の壁に寄せる(左右反転) pts = [(2 * x + w - px, py) for px, py in pts] lx = x + w * 0.7 ax.add_patch(Polygon(pts, closed=True, fc=SEAT, ec=INK, lw=1.2, zorder=3)) label(ax, lx, ly, str(t["seats"]), 11) elif typ == "booth6U": # 右下の6人ボックス(コの字・左が開く) w, h = t["w"], t["h"] pts = [(x, y), (x + w, y), (x + w, y + h), (x, y + h), (x, y + h * 0.75), (x + w * 0.45, y + h * 0.75), (x + w * 0.45, y + h * 0.25), (x, y + h * 0.25)] ax.add_patch(Polygon(pts, closed=True, fc=SEAT, ec=INK, lw=1.2, zorder=3)) label(ax, x + w * 0.72, y + h * 0.5, "6", 11) elif typ == "booth8": # 右下の8人ボックス(コの字) w, h = t["w"], t["h"] pts = [(x, y), (x + w, y), (x + w, y + h), (x, y + h), (x, y + h * 0.78), (x + w * 0.45, y + h * 0.78), (x + w * 0.45, y + h * 0.22), (x, y + h * 0.22)] ax.add_patch(Polygon(pts, closed=True, fc=SEAT, ec=INK, lw=1.2, zorder=3)) label(ax, x + w * 0.72, y + h * 0.5, "8", 11) def main(src, out): L = json.load(open(src, encoding="utf-8")) W, D = L["outer"]["w"], L["outer"]["d"] fig, ax = plt.subplots(figsize=(14, 10.5), dpi=130) ax.set_xlim(-1.0, W + 1.6) ax.set_ylim(-2.2, D + 1.4) ax.set_aspect("equal") ax.axis("off") # 外壁(入口だけ空ける) e0, e1 = L["entrance"]["x0"], L["entrance"]["x1"] ax.plot([0, e0], [0, 0], color=INK, lw=3) ax.plot([e1, W], [0, 0], color=INK, lw=3) ax.plot([0, 0, W, W], [0, D, D, 0], color=INK, lw=3) label(ax, (e0 + e1) / 2, -0.55, "入口", 10, weight="bold") for z in L["zones"]: x0, y0, x1, y1 = z["rect"] ax.text(x0 + 0.15, y1 - 0.25, z["label"], fontsize=9, color=MUTED, va="top", zorder=2) for r in L["rooms"]: fc = {"back": BACK, "guest": "#f8f9fa", "drink": "#d0ebff"}[r["kind"]] ec = DRINK if r["kind"] == "drink" else INK rect(ax, r["rect"], fc, ec=ec, z=2) x0, y0, x1, y1 = r["rect"] vertical = (y1 - y0) > (x1 - x0) * 1.6 text = "\n".join(r["label"]) if vertical else r["label"] label(ax, (x0 + x1) / 2, (y0 + y1) / 2, text, 9 if len(r["label"]) > 3 else 10, DRINK if r["kind"] == "drink" else INK) for a in L.get("aisles", []): # 裏の通路 x0, y0, x1, y1 = a["rect"] text = "\n".join(a["label"]) if (y1 - y0) > (x1 - x0) else a["label"] label(ax, (x0 + x1) / 2, (y0 + y1) / 2, text, 8, MUTED) for w in L["walls"]: rect(ax, w["rect"], "#adb5bd", ec=INK, lw=0.8, hatch="////", z=3) for d in L["dish_up"]: rect(ax, d["rect"], DISH, ec=DISH, z=4) x0, y0, x1, y1 = L["dish_up"][1]["rect"] ax.annotate("料理の受け渡し口", xy=((x0 + x1) / 2, y0), xytext=(7.0, 6.35), fontsize=9, color=DISH, ha="center", arrowprops=dict(arrowstyle="-", color=DISH, lw=1), zorder=6) for t in L["tables"]: draw_table(ax, t) # ロボットの道(主な通り道) for rt in L["robot_routes"]: xs, ys = zip(*rt["path"]) ax.plot(xs, ys, color=ROBOT, lw=1.6, ls=(0, (4, 3)), zorder=4, alpha=0.85) ax.add_patch(FancyArrowPatch(rt["path"][-2], rt["path"][-1], arrowstyle="-|>", mutation_scale=14, color=ROBOT, lw=1.6, zorder=4, alpha=0.85)) # ロボット待機・充電 sb = L["robot_standby"] x0, y0, x1, y1 = sb["rect"] rect(ax, sb["rect"], "#fff4e6", ec=ROBOT, lw=1.6, z=5) n = sb["slots"] for i in range(n): cx = x0 + (x1 - x0) * (i + 0.5) / n ax.add_patch(Circle((cx, (y0 + y1) / 2), 0.26, fc=ROBOT, ec="white", lw=1, zorder=6)) ax.annotate(sb["label"], xy=(x1, (y0 + y1) / 2), xytext=(16.6, 5.55), fontsize=9, color=ROBOT, va="center", arrowprops=dict(arrowstyle="-", color=ROBOT, lw=1), zorder=6) # 縮尺 ax.plot([0, 5], [-1.5, -1.5], color=INK, lw=2) for xx in (0, 5): ax.plot([xx, xx], [-1.65, -1.35], color=INK, lw=2) label(ax, 2.5, -1.85, "5 m", 9) seats = sum(t["seats"] for t in L["tables"]) ax.text(W, -1.5, f"{L['name']} 席数 {seats} 外形 {W:g}m × {D:g}m(仮の寸法)", ha="right", va="center", fontsize=10, color=INK) ax.text(W, -1.95, "オレンジの点線 = ロボットの主な通り道(下の受け渡し口から出る)", ha="right", va="center", fontsize=9, color=ROBOT) fig.savefig(out, bbox_inches="tight", facecolor="white") print("seats", seats) if __name__ == "__main__": main(sys.argv[1], sys.argv[2])