feat(bunsik): 화면 UI 전면 개편 — 시뮬레이터 스타일(굵은 테두리·그러데이션·입체 버튼·직접 그린 아이콘·애니메이션)

- Theme 모듈: 색, 테두리, 입체 버튼(누르면 들어감, PC 마우스 올리면 커짐), 반짝임, 배지
- 아이콘 32개를 직접 그린 한 장(art/ui_icons.png, tools/icons.py)으로 올리고 Icons 모듈로 잘라 씀
- 돈 알약+동전, +돈 떠오름, 네모 아이콘 버튼, 다음 업그레이드 카드(이름표·아이콘·진행 막대),
  업그레이드/설정 창(리본 제목·빨간 X·뒤 어둡게·튀어나오며 열림·다음 줄로 자동 스크롤)
- 손님 말풍선·+돈 글자 테두리 색 통일
- 미리보기 도구: tests/cloud/dump_gui.luau + tools/gui_render.py + tools/preview.sh
- 통합 테스트 668/668, Layout 1522 검사 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-12 17:24:16 +09:00
parent 998b2467d6
commit 05848d19d6
14 changed files with 2604 additions and 449 deletions

View File

@@ -0,0 +1,488 @@
#!/usr/bin/env python3
"""화면 UI 미리보기 그리기: 로블록스 서버에서 만든 ScreenGui를 JSON으로 덤프한 것(tests/cloud/dump_gui.luau)을
cairo로 그립니다. 서버에서는 실제 화면을 볼 수 없어서 배치·색·글자 크기를 눈으로 확인하는 용도입니다.
로블록스 렌더러와 똑같지는 않습니다(글꼴 대체, 글자 크기 맞춤, 3D 배경 없음).
지원: Frame/TextLabel/TextButton/ImageLabel/ImageButton/ScrollingFrame, UDim2·AnchorPoint·Rotation·ZIndex,
UICorner, UIStroke(테두리·글자), UIGradient(색·투명도·회전·오프셋), UIPadding, UIListLayout, UIScale,
UITextSizeConstraint, TextScaled/TextWrapped/정렬, ImageRectOffset/Size, ClipsDescendants.
python3 tools/gui_render.py dump.json out_dir [--bg scene.png]
"""
import json
import math
import os
import sys
import ctypes
import cairo
ROOT_UNUSED = None
class _Rect(ctypes.Structure):
_fields_ = [("x", ctypes.c_int), ("y", ctypes.c_int), ("width", ctypes.c_int), ("height", ctypes.c_int)]
class PangoLib:
"""python3-gi-cairo가 없어서 libpangocairo를 ctypes로 직접 부릅니다(쓰는 함수만)."""
SCALE = 1024
def __init__(self):
self.pc = ctypes.CDLL("libpangocairo-1.0.so.0")
self.p = ctypes.CDLL("libpango-1.0.so.0")
self.g = ctypes.CDLL("libgobject-2.0.so.0")
vp, ci, cs = ctypes.c_void_p, ctypes.c_int, ctypes.c_char_p
for lib, name, res, args in (
(self.pc, "pango_cairo_create_layout", vp, [vp]),
(self.pc, "pango_cairo_show_layout", None, [vp, vp]),
(self.pc, "pango_cairo_layout_path", None, [vp, vp]),
(self.p, "pango_layout_set_text", None, [vp, cs, ci]),
(self.p, "pango_layout_set_width", None, [vp, ci]),
(self.p, "pango_layout_set_wrap", None, [vp, ci]),
(self.p, "pango_layout_set_alignment", None, [vp, ci]),
(self.p, "pango_layout_set_font_description", None, [vp, vp]),
(self.p, "pango_layout_get_pixel_extents", None, [vp, ctypes.POINTER(_Rect), ctypes.POINTER(_Rect)]),
(self.p, "pango_layout_get_line_count", ci, [vp]),
(self.p, "pango_font_description_from_string", vp, [cs]),
(self.p, "pango_font_description_set_weight", None, [vp, ci]),
(self.p, "pango_font_description_set_absolute_size", None, [vp, ctypes.c_double]),
(self.p, "pango_font_description_free", None, [vp]),
(self.g, "g_object_unref", None, [vp]),
):
f = getattr(lib, name)
f.restype = res
f.argtypes = args
@staticmethod
def cr(ctx):
# pycairo Context 객체 안의 cairo_t 포인터(PyObject 머리 16바이트 다음)
return ctypes.c_void_p.from_address(id(ctx) + 16).value
PANGO = PangoLib()
ALIGN = {"Left": 0, "Center": 1, "Right": 2}
WEIGHT = {"SemiBold": 600, "Bold": 700, "Heavy": 900, "Black": 900}
class Layout:
def __init__(self, ctx, family, weight, size, text, width, wrap, align):
P = PANGO
self.ctx = ctx
self.ptr = P.pc.pango_cairo_create_layout(P.cr(ctx))
desc = P.p.pango_font_description_from_string(f"{family}, {FALLBACK}".encode())
P.p.pango_font_description_set_weight(desc, weight)
P.p.pango_font_description_set_absolute_size(desc, max(1.0, size) * P.SCALE)
P.p.pango_layout_set_font_description(self.ptr, desc)
P.p.pango_font_description_free(desc)
P.p.pango_layout_set_text(self.ptr, text.encode(), -1)
if wrap:
P.p.pango_layout_set_width(self.ptr, int(max(1, width) * P.SCALE))
P.p.pango_layout_set_wrap(self.ptr, 2) # WORD_CHAR
P.p.pango_layout_set_alignment(self.ptr, ALIGN.get(align, 1))
def extents(self):
ink, logical = _Rect(), _Rect()
PANGO.p.pango_layout_get_pixel_extents(self.ptr, ctypes.byref(ink), ctypes.byref(logical))
return ink, logical
def lines(self):
return PANGO.p.pango_layout_get_line_count(self.ptr)
def path(self, ctx):
PANGO.pc.pango_cairo_layout_path(PANGO.cr(ctx), self.ptr)
def show(self, ctx):
PANGO.pc.pango_cairo_show_layout(PANGO.cr(ctx), self.ptr)
def __del__(self):
PANGO.g.g_object_unref(self.ptr)
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
IMAGES = {} # rbxassetid 숫자 -> 로컬 png 경로 (Icons.luau의 ID와 art/ui_icons.png)
FONT_FAMILY = {
"FredokaOne": "Fredoka SemiBold",
"LuckiestGuy": "Luckiest Guy",
"Bangers": "Luckiest Guy",
"GothamBlack": "Noto Sans Black",
"BuilderSans": "Noto Sans",
"Montserrat": "Noto Sans",
}
# 한글·한자·이모지는 로블록스도 대체 글꼴로 그립니다.
FALLBACK = "Noto Sans CJK KR, Noto Color Emoji"
def surface_png(path):
return cairo.ImageSurface.create_from_png(path)
_img_cache = {}
def image_surface(asset):
num = "".join(ch for ch in str(asset) if ch.isdigit())
path = IMAGES.get(num)
if not path:
return None
if path not in _img_cache:
_img_cache[path] = surface_png(path)
return _img_cache[path]
def udim(u, size, k):
return u[0] * size + u[1] * k
def round_rect(c, x, y, w, h, r):
r = max(0, min(r, w / 2, h / 2))
if r <= 0.01:
c.rectangle(x, y, w, h)
return
c.new_sub_path()
c.arc(x + w - r, y + r, r, -math.pi / 2, 0)
c.arc(x + w - r, y + h - r, r, 0, math.pi / 2)
c.arc(x + r, y + h - r, r, math.pi / 2, math.pi)
c.arc(x + r, y + r, r, math.pi, 3 * math.pi / 2)
c.close_path()
def gradient_pattern(g, x, y, w, h, base, alpha):
"""UIGradient를 cairo 패턴으로. base(색)·alpha(불투명도)에 곱합니다."""
rot = math.radians(g.get("Rotation", 0))
ox, oy = g.get("Offset", [0, 0])
cx, cy = x + w / 2 + ox * w, y + h / 2 + oy * h
dx, dy = math.cos(rot), math.sin(rot)
# 회전된 방향으로 상자를 덮는 길이
half = (abs(dx) * w + abs(dy) * h) / 2
pat = cairo.LinearGradient(cx - dx * half, cy - dy * half, cx + dx * half, cy + dy * half)
colors = g.get("Color") or [[0, [1, 1, 1]], [1, [1, 1, 1]]]
trans = g.get("Transparency") or [[0, 0], [1, 0]]
times = sorted(set([t for t, _ in colors] + [t for t, _ in trans]))
def at(seq, t):
for i in range(len(seq) - 1):
t0, v0 = seq[i]
t1, v1 = seq[i + 1]
if t0 <= t <= t1:
f = 0 if t1 == t0 else (t - t0) / (t1 - t0)
if isinstance(v0, list):
return [v0[j] + (v1[j] - v0[j]) * f for j in range(3)]
return v0 + (v1 - v0) * f
return seq[-1][1] if t >= seq[-1][0] else seq[0][1]
for t in times:
col = at(colors, t)
tr = at(trans, t)
pat.add_color_stop_rgba(t, base[0] * col[0], base[1] * col[1], base[2] * col[2], alpha * (1 - tr))
return pat
class Renderer:
def __init__(self, c):
self.c = c
# ---------------------------------------------------------------- 배치
def children_rects(self, node, rect, k):
"""자식 GuiObject의 (자식, x, y, w, h, k) 목록. UIListLayout·UIPadding·UIScale 반영."""
x, y, w, h = rect
pad = node.get("UIPadding")
if pad:
pl = udim(pad["Left"], w, k)
pr = udim(pad["Right"], w, k)
pt = udim(pad["Top"], h, k)
pb = udim(pad["Bottom"], h, k)
x, y, w, h = x + pl, y + pt, w - pl - pr, h - pt - pb
out = []
kids = [ch for ch in node.get("children", []) if ch.get("Visible", True)]
for ch in kids:
s = ch.get("UIScale", 1)
cw = udim(ch["Size"][0], w, k) * s
chh = udim(ch["Size"][1], h, k) * s
ar = ch.get("UIAspectRatio")
if ar:
if cw / max(chh, 1e-6) > ar:
cw = chh * ar
else:
chh = cw / ar
out.append([ch, cw, chh, k * s])
lay = node.get("UIListLayout")
if lay:
horiz = lay.get("FillDirection") == "Horizontal"
gap = udim(lay.get("Padding", [0, 0]), w if horiz else h, k)
items = sorted(out, key=lambda o: (o[0].get("LayoutOrder", 0), o[0].get("_i", 0))) \
if lay.get("SortOrder") == "LayoutOrder" else sorted(out, key=lambda o: o[0].get("Name", ""))
total = sum((o[1] if horiz else o[2]) for o in items) + gap * max(0, len(items) - 1)
ha = lay.get("HorizontalAlignment", "Left")
va = lay.get("VerticalAlignment", "Top")
if horiz:
cur = x + {"Left": 0, "Center": (w - total) / 2, "Right": w - total}[ha]
else:
cur = y + {"Top": 0, "Center": (h - total) / 2, "Bottom": h - total}[va]
res = []
for ch, cw, chh, kk in items:
if horiz:
cy = y + {"Top": 0, "Center": (h - chh) / 2, "Bottom": h - chh}[va]
res.append((ch, cur, cy, cw, chh, kk))
cur += cw + gap
else:
cx = x + {"Left": 0, "Center": (w - cw) / 2, "Right": w - cw}[ha]
res.append((ch, cx, cur, cw, chh, kk))
cur += chh + gap
return res
res = []
for ch, cw, chh, kk in out:
s = ch.get("UIScale", 1)
# UIScale은 AnchorPoint를 기준으로 크기를 바꿉니다.
bw, bh = cw / s, chh / s
ax, ay = ch.get("AnchorPoint", [0, 0])
px = x + udim(ch["Position"][0], w, k) - ax * bw
py = y + udim(ch["Position"][1], h, k) - ay * bh
px -= (cw - bw) * ax
py -= (chh - bh) * ay
res.append((ch, px, py, cw, chh, kk))
return res
# ---------------------------------------------------------------- 그리기
def draw_node(self, node, x, y, w, h, k):
c = self.c
c.save()
rot = node.get("Rotation", 0)
if rot:
c.translate(x + w / 2, y + h / 2)
c.rotate(math.radians(rot))
c.translate(-(x + w / 2), -(y + h / 2))
corner = node.get("UICorner")
r = udim(corner, min(w, h), k) if corner else 0
grad = node.get("UIGradient")
bt = node.get("BackgroundTransparency", 1)
if bt < 1 and node["ClassName"] not in ("ScreenGui",):
base = node.get("BackgroundColor3", [1, 1, 1])
round_rect(c, x, y, w, h, r)
if grad:
c.set_source(gradient_pattern(grad, x, y, w, h, base, 1 - bt))
else:
c.set_source_rgba(*base, 1 - bt)
c.fill()
img = node.get("Image")
if img:
self.draw_image(node, x, y, w, h, r, grad)
if "Text" in node and node.get("Text"):
self.draw_text(node, x, y, w, h, k, grad)
for st in node.get("UIStrokes", []):
if st.get("ApplyStrokeMode") == "Border" and st.get("Enabled", True):
t = st["Thickness"] * k
round_rect(c, x - t / 2, y - t / 2, w + t, h + t, r + t / 2 if r > 0 else 0)
c.set_line_width(t)
c.set_line_join(cairo.LINE_JOIN_ROUND)
sg = st.get("UIGradient")
if sg:
c.set_source(gradient_pattern(sg, x, y, w, h, st["Color"], 1 - st.get("Transparency", 0)))
else:
c.set_source_rgba(*st["Color"], 1 - st.get("Transparency", 0))
c.stroke()
if node.get("ClipsDescendants") or node["ClassName"] == "ScrollingFrame":
round_rect(c, x, y, w, h, r)
c.clip()
cpx, cpy = node.get("CanvasPosition", [0, 0])
kids = self.children_rects(node, (x - cpx * k, y - cpy * k, w, h), k)
kids.sort(key=lambda t: (t[0].get("ZIndex", 1), t[0].get("_i", 0)))
for ch, cx, cy, cw, chh, kk in kids:
self.draw_node(ch, cx, cy, cw, chh, kk)
c.restore()
def draw_image(self, node, x, y, w, h, r, grad):
surf = image_surface(node["Image"])
c = self.c
if surf is None:
c.rectangle(x, y, w, h)
c.set_source_rgba(1, 0, 1, 0.5)
c.fill()
return
ox, oy = node.get("ImageRectOffset", [0, 0])
sw, sh = node.get("ImageRectSize", [0, 0])
if sw == 0 or sh == 0:
sw, sh = surf.get_width(), surf.get_height()
dw, dh = w, h
if node.get("ScaleType") == "Fit":
s = min(w / sw, h / sh)
dw, dh = sw * s, sh * s
dx, dy = x + (w - dw) / 2, y + (h - dh) / 2
c.save()
round_rect(c, x, y, w, h, r)
c.clip()
c.translate(dx, dy)
c.scale(dw / sw, dh / sh)
c.translate(-ox, -oy)
alpha = 1 - node.get("ImageTransparency", 0)
col = node.get("ImageColor3", [1, 1, 1])
c.rectangle(ox, oy, sw, sh)
c.clip()
if col != [1, 1, 1] or grad:
# 색 곱하기: 그림을 마스크로 쓰고 색을 곱한 그림을 그립니다.
tmp = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(sw), int(sh))
tc = cairo.Context(tmp)
tc.set_source_surface(surf, -ox, -oy)
tc.paint()
tc.set_operator(cairo.OPERATOR_MULTIPLY)
if grad:
tc.set_source(gradient_pattern(grad, 0, 0, sw, sh, col, 1))
else:
tc.set_source_rgb(*col)
tc.paint()
tc.set_operator(cairo.OPERATOR_DEST_IN)
tc.set_source_surface(surf, -ox, -oy)
tc.paint()
c.set_source_surface(tmp, ox, oy)
else:
c.set_source_surface(surf, 0, 0)
c.get_source().set_filter(cairo.FILTER_GOOD)
c.paint_with_alpha(alpha)
c.restore()
def layout_text(self, node, size, width, wrap):
fam = FONT_FAMILY.get(node.get("Font", "FredokaOne"), "Noto Sans")
weight = WEIGHT.get(node.get("Weight", ""), 400)
if fam.startswith("Fredoka"):
weight = 600
elif "Black" in fam:
weight = 900
align = node.get("TextXAlignment", "Center")
return Layout(self.c, fam.replace(" SemiBold", "").replace(" Black", ""), weight, size, node["Text"], width,
wrap, align)
def draw_text(self, node, x, y, w, h, k, grad):
c = self.c
pad = node.get("UIPadding")
if pad:
pl, pr = udim(pad["Left"], w, k), udim(pad["Right"], w, k)
pt, pb = udim(pad["Top"], h, k), udim(pad["Bottom"], h, k)
x, y, w, h = x + pl, y + pt, w - pl - pr, h - pt - pb
wrap = node.get("TextWrapped", False) or node.get("TextScaled", False)
maxsize = node.get("MaxTextSize", 100)
if node.get("TextScaled"):
lo, hi = 1, min(maxsize, 100) * k
best = lo
while hi - lo > 0.5:
mid = (lo + hi) / 2
lay = self.layout_text(node, mid, w, wrap)
ink, logical = lay.extents()
# 단어 중간에서 줄이 끊기면 안 맞는 것으로 봅니다(로블록스 TextScaled와 비슷하게).
words_ok = lay.lines() <= max(1, len(node["Text"].split())) + node["Text"].count("\n")
if logical.width <= w + 0.5 and logical.height <= h + 0.5 and words_ok:
best = mid
lo = mid
else:
hi = mid
size = best
else:
size = node.get("TextSize", 14) * k
lay = self.layout_text(node, size, w, wrap)
ink, logical = lay.extents()
ya = node.get("TextYAlignment", "Center")
ty = y + {"Top": 0, "Center": (h - logical.height) / 2, "Bottom": h - logical.height}[ya]
tx = x
if not wrap:
xa = node.get("TextXAlignment", "Center")
tx = x + {"Left": 0, "Center": (w - logical.width) / 2, "Right": w - logical.width}[xa]
c.save()
c.move_to(tx, ty)
lay.path(c)
alpha = 1 - node.get("TextTransparency", 0)
for st in node.get("UIStrokes", []):
if st.get("ApplyStrokeMode", "Contextual") == "Contextual" and st.get("Enabled", True):
c.set_line_width(st["Thickness"] * k * 2)
c.set_line_join(cairo.LINE_JOIN_ROUND)
c.set_source_rgba(*st["Color"], alpha * (1 - st.get("Transparency", 0)))
c.stroke_preserve()
if node.get("TextStrokeTransparency", 1) < 1:
c.set_line_width(2 * k)
c.set_source_rgba(*node.get("TextStrokeColor3", [0, 0, 0]), alpha * (1 - node["TextStrokeTransparency"]))
c.stroke_preserve()
c.new_path()
c.restore()
# 글자 채우기(이모지 색을 살리려고 path 대신 show_layout)
c.save()
col = node.get("TextColor3", [0, 0, 0])
if grad and node.get("TextGradient", True):
c.push_group()
c.move_to(tx, ty)
c.set_source_rgba(1, 1, 1, alpha)
lay.show(c)
mask = c.pop_group()
c.set_source(gradient_pattern(grad, x, y, w, h, col, 1))
c.mask(mask)
else:
c.move_to(tx, ty)
c.set_source_rgba(*col, alpha)
lay.show(c)
c.restore()
def render(dump, out, bg=None):
W, H, inset = dump["width"], dump["height"], dump.get("inset", 0)
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(W), int(H + inset))
c = cairo.Context(surf)
if bg and os.path.exists(bg):
b = surface_png(bg)
c.save()
c.scale(W / b.get_width(), (H + inset) / b.get_height())
c.set_source_surface(b, 0, 0)
c.paint()
c.restore()
else:
g = cairo.LinearGradient(0, 0, 0, H + inset)
g.add_color_stop_rgb(0, 0.55, 0.78, 0.95)
g.add_color_stop_rgb(0.55, 0.75, 0.88, 0.98)
g.add_color_stop_rgb(0.56, 0.42, 0.66, 0.36)
g.add_color_stop_rgb(1, 0.33, 0.55, 0.28)
c.set_source(g)
c.paint()
# 로블록스 상단 바(대략)
if inset:
c.set_source_rgba(0, 0, 0, 0.25)
for i, x in enumerate((12, 60)):
round_rect(c, x, 10, 40, 40, 10)
c.fill()
touch = dump.get("touch")
if touch and dump.get("zones"):
for z in dump["zones"].values():
c.set_source_rgba(1, 1, 1, 0.12)
c.rectangle(z["x"], z["y"] + inset, z["w"], z["h"])
c.fill()
# 조이스틱·점프 버튼 모양(대략)
st = dump["zones"]["stick"]
c.arc(st["x"] + 110, inset + H - 110, 60, 0, 2 * math.pi)
c.set_source_rgba(0, 0, 0, 0.3)
c.fill()
jp = dump["zones"]["jump"]
jr = min(jp["w"], jp["h"]) * 0.3
c.arc(jp["x"] + jp["w"] * 0.55, inset + jp["y"] + jp["h"] * 0.55, jr, 0, 2 * math.pi)
c.fill()
r = Renderer(c)
gui = dump["gui"]
c.translate(0, inset)
for ch, x, y, w, h, k in r.children_rects(gui, (0, 0, W, H), 1):
r.draw_node(ch, x, y, w, h, k)
surf.write_to_png(out)
def main(argv):
src, outdir = argv[0], argv[1]
bg = argv[argv.index("--bg") + 1] if "--bg" in argv else None
with open(src) as f:
data = json.load(f)
for num, path in data.get("images", {}).items():
IMAGES[str(num)] = os.path.join(ROOT, path)
os.makedirs(outdir, exist_ok=True)
for shot in data["shots"]:
out = os.path.join(outdir, shot["name"] + ".png")
render(shot, out, bg)
print(out)
if __name__ == "__main__":
main(sys.argv[1:])

View File

@@ -0,0 +1,719 @@
#!/usr/bin/env python3
"""화면 UI 아이콘 모음(1024x1024, 128px 칸 8x8)을 직접 그립니다. 외부 그림을 쓰지 않습니다.
로블록스에는 이 한 장만 올리고, 각 아이콘은 ImageRectOffset/ImageRectSize로 잘라 씁니다.
칸 이름과 위치는 src/shared/Icons.luau 와 같아야 합니다(tools/icons.py --luau 로 확인).
python3 tools/icons.py # art/ui_icons.png
python3 tools/icons.py --sheet x.png # 이름표가 붙은 확인용 그림
"""
import math
import os
import sys
import cairo
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "art", "ui_icons.png")
CELL = 128
GRID = 8
INK = (0.23, 0.12, 0.07) # 테두리(진한 갈색)
LW = 7 # 테두리 굵기
def rgb(h):
h = h.lstrip("#")
return tuple(int(h[i:i + 2], 16) / 255 for i in (0, 2, 4))
def lin(x0, y0, x1, y1, *stops):
g = cairo.LinearGradient(x0, y0, x1, y1)
for i, c in enumerate(stops):
g.add_color_stop_rgb(i / max(1, len(stops) - 1), *rgb(c))
return g
def rad(cx, cy, r, *stops):
g = cairo.RadialGradient(cx - r * 0.3, cy - r * 0.35, r * 0.1, cx, cy, r)
for i, c in enumerate(stops):
g.add_color_stop_rgb(i / max(1, len(stops) - 1), *rgb(c))
return g
def fill_stroke(c, paint, lw=LW):
c.set_source(paint) if isinstance(paint, cairo.Pattern) else c.set_source_rgb(*paint)
c.fill_preserve()
c.set_source_rgb(*INK)
c.set_line_width(lw)
c.set_line_join(cairo.LINE_JOIN_ROUND)
c.set_line_cap(cairo.LINE_CAP_ROUND)
c.stroke()
def rrect(c, x, y, w, h, r):
c.new_sub_path()
c.arc(x + w - r, y + r, r, -math.pi / 2, 0)
c.arc(x + w - r, y + h - r, r, 0, math.pi / 2)
c.arc(x + r, y + h - r, r, math.pi / 2, math.pi)
c.arc(x + r, y + r, r, math.pi, 3 * math.pi / 2)
c.close_path()
def shine(c, x, y, w, h, alpha=0.55):
"""왼쪽 위 흰 반사광(타원 조각)."""
c.save()
c.translate(x, y)
c.scale(w, h)
c.arc(0, 0, 1, 0, 2 * math.pi)
c.restore()
c.set_source_rgba(1, 1, 1, alpha)
c.fill()
def polygon(c, pts):
c.move_to(*pts[0])
for p in pts[1:]:
c.line_to(*p)
c.close_path()
def star_pts(cx, cy, r1, r2, n=5, rot=-math.pi / 2):
pts = []
for i in range(n * 2):
r = r1 if i % 2 == 0 else r2
a = rot + i * math.pi / n
pts.append((cx + r * math.cos(a), cy + r * math.sin(a)))
return pts
# ---------------------------------------------------------------- 아이콘들 (64x64 중심, 128 칸)
def coin(c):
c.arc(64, 66, 50, 0, 2 * math.pi)
fill_stroke(c, rad(64, 66, 56, "#fff3a0", "#ffd23a", "#f59e0b"))
c.arc(64, 66, 36, 0, 2 * math.pi)
c.set_source(lin(0, 30, 0, 100, "#f5a70b", "#ffd84a"))
c.fill_preserve()
c.set_source_rgba(*INK, 0.35)
c.set_line_width(3)
c.stroke()
# ₩
c.set_source_rgb(*rgb("#b45309"))
c.set_line_width(8)
c.set_line_cap(cairo.LINE_CAP_ROUND)
c.set_line_join(cairo.LINE_JOIN_ROUND)
c.move_to(44, 47)
c.line_to(53, 87)
c.line_to(64, 57)
c.line_to(75, 87)
c.line_to(84, 47)
c.stroke()
c.set_line_width(5)
for y in (64, 74):
c.move_to(41, y)
c.line_to(87, y)
c.stroke()
shine(c, 44, 40, 14, 8, 0.7)
def money_bag(c):
c.move_to(46, 30)
c.curve_to(30, 50, 14, 74, 22, 96)
c.curve_to(28, 116, 100, 116, 106, 96)
c.curve_to(114, 74, 98, 50, 82, 30)
c.close_path()
fill_stroke(c, rad(64, 76, 56, "#c7f59a", "#6cc63c", "#3f8f25"))
rrect(c, 42, 16, 44, 18, 8)
fill_stroke(c, lin(0, 16, 0, 34, "#a5e57a", "#4f9f2c"))
c.set_source_rgb(*rgb("#ffd23a"))
c.set_line_width(7)
c.move_to(44, 36)
c.line_to(84, 36)
c.stroke()
# ₩ 표시
c.set_source_rgb(*rgb("#2f6f17"))
c.set_line_width(7)
c.set_line_cap(cairo.LINE_CAP_ROUND)
c.move_to(46, 62)
c.line_to(54, 94)
c.line_to(64, 70)
c.line_to(74, 94)
c.line_to(82, 62)
c.stroke()
c.set_line_width(4)
c.move_to(43, 76)
c.line_to(85, 76)
c.stroke()
shine(c, 40, 62, 8, 14, 0.5)
def bolt(c):
polygon(c, [(74, 8), (26, 72), (58, 72), (48, 120), (102, 50), (68, 50), (82, 8)])
fill_stroke(c, lin(30, 10, 90, 120, "#fff6a8", "#ffd21f", "#ff9f0a"))
polygon(c, [(72, 18), (40, 64), (52, 64)])
c.set_source_rgba(1, 1, 1, 0.6)
c.fill()
def gear(c):
teeth = 8
pts = []
for i in range(teeth * 4):
a = i * 2 * math.pi / (teeth * 4) - math.pi / 2
r = 54 if (i % 4) in (0, 1) else 40
pts.append((64 + r * math.cos(a + math.pi / (teeth * 4)), 64 + r * math.sin(a + math.pi / (teeth * 4))))
polygon(c, pts)
c.new_sub_path()
c.arc_negative(64, 64, 17, 0, -2 * math.pi)
c.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
fill_stroke(c, rad(64, 64, 58, "#f1f5f9", "#a8b4c4", "#64748b"))
c.set_fill_rule(cairo.FILL_RULE_WINDING)
shine(c, 46, 42, 10, 6, 0.6)
def upgrade(c):
# 초록 위쪽 화살표
polygon(c, [(64, 8), (114, 60), (84, 60), (84, 116), (44, 116), (44, 60), (14, 60)])
fill_stroke(c, lin(0, 8, 0, 116, "#b6f774", "#46c937", "#178a2c"))
polygon(c, [(64, 22), (34, 54), (50, 54)])
c.set_source_rgba(1, 1, 1, 0.55)
c.fill()
def plate(c):
c.save()
c.translate(64, 76)
c.scale(1, 0.5)
c.arc(0, 0, 56, 0, 2 * math.pi)
c.restore()
fill_stroke(c, lin(0, 50, 0, 104, "#ffffff", "#d7dde6"))
c.save()
c.translate(64, 74)
c.scale(1, 0.5)
c.arc(0, 0, 36, 0, 2 * math.pi)
c.restore()
c.set_source_rgba(*INK, 0.25)
c.set_line_width(3)
c.stroke()
# 김 나는 음식
c.move_to(36, 72)
c.curve_to(36, 36, 92, 36, 92, 72)
c.close_path()
fill_stroke(c, lin(0, 40, 0, 72, "#ff7a59", "#e63b1f"))
for x in (52, 64, 76):
c.move_to(x, 30)
c.curve_to(x - 6, 22, x + 6, 16, x, 8)
c.set_source_rgba(1, 1, 1, 0.9)
c.set_line_width(4)
c.stroke()
def lock(c):
c.arc(64, 50, 26, math.pi, 2 * math.pi)
c.set_line_width(14 + LW)
c.set_source_rgb(*INK)
c.stroke()
c.arc(64, 50, 26, math.pi, 2 * math.pi)
c.set_line_width(13)
c.set_source_rgb(*rgb("#cbd5e1"))
c.stroke()
rrect(c, 26, 50, 76, 64, 14)
fill_stroke(c, lin(0, 50, 0, 114, "#ffe066", "#f59e0b"))
c.arc(64, 76, 9, 0, 2 * math.pi)
c.set_source_rgb(*INK)
c.fill()
rrect(c, 60, 78, 8, 20, 4)
c.fill()
def check(c):
c.set_line_cap(cairo.LINE_CAP_ROUND)
c.set_line_join(cairo.LINE_JOIN_ROUND)
for w, col in ((30, INK), (18, rgb("#4ade80"))):
c.move_to(22, 66)
c.line_to(52, 96)
c.line_to(106, 34)
c.set_line_width(w)
c.set_source_rgb(*col)
c.stroke()
def close_x(c):
c.set_line_cap(cairo.LINE_CAP_ROUND)
for w, col in ((32, INK), (19, (1, 1, 1))):
c.set_line_width(w)
c.set_source_rgb(*col)
c.move_to(30, 30)
c.line_to(98, 98)
c.move_to(98, 30)
c.line_to(30, 98)
c.stroke()
def table(c):
# 다리
for x in (30, 92):
rrect(c, x, 58, 12, 56, 4)
fill_stroke(c, lin(0, 58, 0, 114, "#b9763c", "#7a4a22"), 5)
c.save()
c.translate(64, 52)
c.scale(1, 0.42)
c.arc(0, 0, 58, 0, 2 * math.pi)
c.restore()
fill_stroke(c, lin(0, 28, 0, 76, "#f2b46b", "#c97b36"))
c.save()
c.translate(64, 50)
c.scale(1, 0.42)
c.arc(0, 0, 42, 0, 2 * math.pi)
c.restore()
c.set_source_rgba(1, 1, 1, 0.3)
c.fill()
def sign(c):
for x in (34, 90):
rrect(c, x, 70, 8, 50, 3)
fill_stroke(c, rgb("#7a4a22"), 5)
rrect(c, 10, 16, 108, 64, 14)
fill_stroke(c, lin(0, 16, 0, 80, "#ff6b4a", "#d92f1c"))
rrect(c, 20, 26, 88, 44, 8)
c.set_source_rgb(*rgb("#fff3d6"))
c.fill()
for i, x in enumerate((40, 64, 88)):
polygon(c, star_pts(x, 48, 13, 6))
fill_stroke(c, rgb("#ffc61a"), 3)
def flame(c):
c.move_to(64, 6)
c.curve_to(96, 40, 112, 62, 108, 86)
c.curve_to(104, 112, 84, 122, 64, 122)
c.curve_to(40, 122, 20, 108, 20, 84)
c.curve_to(20, 64, 34, 52, 40, 34)
c.curve_to(48, 50, 52, 54, 56, 56)
c.curve_to(56, 36, 58, 22, 64, 6)
c.close_path()
fill_stroke(c, lin(0, 6, 0, 122, "#ffd23a", "#ff7a1a", "#e8341c"))
c.move_to(64, 58)
c.curve_to(82, 76, 88, 88, 84, 100)
c.curve_to(80, 114, 48, 114, 44, 100)
c.curve_to(42, 88, 54, 78, 64, 58)
c.close_path()
c.set_source(lin(0, 58, 0, 114, "#fff8c2", "#ffd23a"))
c.fill()
def sauce(c):
rrect(c, 52, 6, 24, 20, 6)
fill_stroke(c, rgb("#ffffff"), 5)
c.move_to(48, 26)
c.line_to(80, 26)
c.curve_to(80, 40, 100, 44, 100, 64)
c.line_to(100, 108)
c.curve_to(100, 118, 94, 122, 86, 122)
c.line_to(42, 122)
c.curve_to(34, 122, 28, 118, 28, 108)
c.line_to(28, 64)
c.curve_to(28, 44, 48, 40, 48, 26)
c.close_path()
fill_stroke(c, lin(28, 0, 100, 0, "#ff5a3c", "#d61f12", "#a8150b"))
rrect(c, 38, 66, 52, 36, 8)
c.set_source_rgb(*rgb("#fff3d6"))
c.fill()
polygon(c, [(64, 72), (72, 84), (64, 96), (56, 84)])
c.set_source_rgb(*rgb("#e8341c"))
c.fill()
c.rectangle(36, 46, 8, 52)
c.set_source_rgba(1, 1, 1, 0.45)
c.fill()
def chef(c):
# 요리사 모자
for x, y, r in ((40, 46, 24), (64, 34, 28), (88, 46, 24)):
c.arc(x, y, r, 0, 2 * math.pi)
c.set_source_rgb(*INK)
c.fill()
rrect(c, 34, 56, 60, 52, 8)
fill_stroke(c, lin(0, 56, 0, 108, "#ffffff", "#dfe5ee"))
for x, y, r in ((40, 46, 24 - LW / 2), (64, 34, 28 - LW / 2), (88, 46, 24 - LW / 2)):
c.arc(x, y, r, 0, 2 * math.pi)
c.set_source(rad(x, y, r + 4, "#ffffff", "#e6ebf2"))
c.fill()
rrect(c, 34 + LW / 2, 60, 60 - LW, 20, 4)
c.set_source_rgb(1, 1, 1)
c.fill()
for x in (52, 64, 76):
c.move_to(x, 86)
c.line_to(x, 104)
c.set_source_rgba(*INK, 0.3)
c.set_line_width(3)
c.stroke()
def store(c):
rrect(c, 18, 54, 92, 64, 6)
fill_stroke(c, lin(0, 54, 0, 118, "#fff3d6", "#f2d7a8"))
# 줄무늬 차양
polygon(c, [(10, 56), (22, 18), (106, 18), (118, 56)])
c.set_source_rgb(*INK)
c.set_line_width(LW)
c.stroke_preserve()
c.save()
c.clip()
for i in range(7):
polygon(c, [(10 + i * 18, 56), (22 + i * 12, 18), (34 + i * 12, 18), (28 + i * 18, 56)])
c.set_source_rgb(*(rgb("#e8341c") if i % 2 == 0 else (1, 1, 1)))
c.fill()
c.restore()
polygon(c, [(10, 56), (22, 18), (106, 18), (118, 56)])
c.set_source_rgb(*INK)
c.set_line_width(LW)
c.stroke()
rrect(c, 52, 76, 24, 42, 4)
fill_stroke(c, rgb("#b9763c"), 5)
rrect(c, 26, 70, 18, 18, 3)
fill_stroke(c, rgb("#8fd3ff"), 4)
rrect(c, 84, 70, 18, 18, 3)
fill_stroke(c, rgb("#8fd3ff"), 4)
def tray(c):
polygon(c, [(8, 70), (120, 70), (108, 98), (20, 98)])
fill_stroke(c, lin(0, 70, 0, 98, "#e2e8f0", "#94a3b8"))
for x, col in ((40, "#ff6b4a"), (64, "#ffd23a"), (88, "#7dd36b")):
c.move_to(x - 16, 68)
c.curve_to(x - 16, 44, x + 16, 44, x + 16, 68)
c.close_path()
fill_stroke(c, rgb(col), 5)
shine(c, 30, 80, 14, 4, 0.6)
def tteokbokki(c):
# 그릇
c.move_to(10, 58)
c.line_to(118, 58)
c.curve_to(116, 96, 92, 118, 64, 118)
c.curve_to(36, 118, 12, 96, 10, 58)
c.close_path()
fill_stroke(c, lin(0, 58, 0, 118, "#ffffff", "#cfd8e3"))
# 소스
c.save()
c.translate(64, 58)
c.scale(1, 0.32)
c.arc(0, 0, 52, 0, 2 * math.pi)
c.restore()
c.set_source_rgb(*rgb("#e8341c"))
c.fill()
# 떡
for x, y, a in ((40, 46, -0.5), (64, 40, 0.3), (86, 48, -0.2), (54, 56, 0.1), (78, 58, -0.4)):
c.save()
c.translate(x, y)
c.rotate(a)
rrect(c, -16, -8, 32, 16, 8)
c.restore()
fill_stroke(c, lin(0, y - 8, 0, y + 8, "#ff8a6a", "#d92f1c"), 4)
c.save()
c.translate(x, y)
c.rotate(a)
rrect(c, -10, -5, 14, 4, 2)
c.restore()
c.set_source_rgba(1, 1, 1, 0.6)
c.fill()
shine(c, 26, 80, 6, 12, 0.5)
def gimbap(c):
for x, y in ((40, 74), (88, 74), (64, 50)):
c.arc(x, y, 26, 0, 2 * math.pi)
fill_stroke(c, rgb("#1f2a1f"), 5)
c.arc(x, y, 19, 0, 2 * math.pi)
c.set_source_rgb(1, 1, 1)
c.fill()
for dx, dy, col in ((-6, -5, "#ff8c1a"), (6, -4, "#ffd23a"), (0, 6, "#4caf50"), (-7, 6, "#e8341c")):
c.arc(x + dx, y + dy, 5, 0, 2 * math.pi)
c.set_source_rgb(*rgb(col))
c.fill()
def sundae(c):
for x, y in ((38, 80), (64, 60), (90, 80)):
c.arc(x, y, 26, 0, 2 * math.pi)
fill_stroke(c, rad(x, y, 30, "#8a5a6a", "#5a2e3c", "#3a1a24"), 5)
for dx, dy in ((-8, -6), (6, -8), (8, 6), (-6, 8), (0, 0)):
c.arc(x + dx, y + dy, 3, 0, 2 * math.pi)
c.set_source_rgba(1, 0.85, 0.8, 0.7)
c.fill()
def eomuk(c):
c.set_line_cap(cairo.LINE_CAP_ROUND)
for w, col in ((10 + LW, INK), (8, rgb("#e8c58f"))):
c.move_to(64, 6)
c.line_to(64, 124)
c.set_line_width(w)
c.set_source_rgb(*col)
c.stroke()
# 꼬치에 접어 꽂은 어묵(지그재그 세 겹)
for i, (dx, a) in enumerate(((-8, -0.12), (8, 0.12), (-8, -0.12))):
y = 30 + i * 28
c.save()
c.translate(64 + dx, y)
c.rotate(a)
rrect(c, -40, -14, 80, 28, 12)
c.restore()
fill_stroke(c, lin(0, y - 14, 0, y + 14, "#ffe2a8", "#f2b46b", "#d98a3a"), 6)
c.save()
c.translate(64 + dx, y)
c.rotate(a)
rrect(c, -32, -9, 40, 5, 2.5)
c.restore()
c.set_source_rgba(1, 1, 1, 0.55)
c.fill()
def twigim(c):
# 새우튀김
c.save()
c.translate(64, 64)
c.rotate(-0.7)
c.move_to(-52, 0)
c.curve_to(-52, -26, 30, -26, 40, -6)
c.line_to(40, 6)
c.curve_to(30, 26, -52, 26, -52, 0)
c.close_path()
c.restore()
fill_stroke(c, lin(20, 20, 110, 110, "#ffe28a", "#f5a524", "#c9761a"))
c.save()
c.translate(64, 64)
c.rotate(-0.7)
polygon(c, [(38, -2), (60, -18), (54, 0), (60, 18), (38, 2)])
c.restore()
fill_stroke(c, rgb("#ff6b4a"), 5)
for x, y in ((40, 74), (54, 62), (68, 50), (48, 86), (62, 74), (76, 62), (34, 62)):
c.arc(x, y, 3.5, 0, 2 * math.pi)
c.set_source_rgba(1, 1, 1, 0.55)
c.fill()
def globe(c):
c.arc(64, 64, 52, 0, 2 * math.pi)
fill_stroke(c, rad(64, 64, 58, "#a8e6ff", "#38a8f5", "#1769c4"))
c.save()
c.arc(64, 64, 52 - LW / 2, 0, 2 * math.pi)
c.clip()
c.set_source(lin(0, 0, 0, 128, "#86e06a", "#3fa33a"))
c.move_to(30, 30)
c.curve_to(50, 20, 60, 40, 52, 56)
c.curve_to(44, 70, 22, 64, 18, 52)
c.close_path()
c.fill()
c.move_to(70, 60)
c.curve_to(94, 50, 112, 70, 100, 92)
c.curve_to(90, 108, 70, 100, 72, 84)
c.close_path()
c.fill()
c.restore()
c.set_source_rgba(*INK, 0.35)
c.set_line_width(3)
c.save()
c.translate(64, 64)
c.scale(0.45, 1)
c.arc(0, 0, 52, 0, 2 * math.pi)
c.restore()
c.stroke()
c.move_to(12, 64)
c.line_to(116, 64)
c.stroke()
shine(c, 44, 40, 12, 8, 0.6)
def speaker(c):
polygon(c, [(14, 48), (38, 48), (68, 20), (68, 108), (38, 80), (14, 80)])
fill_stroke(c, lin(0, 20, 0, 108, "#ffe066", "#f59e0b"))
c.set_line_cap(cairo.LINE_CAP_ROUND)
for r in (22, 40):
for w, col in ((9 + LW, INK), (9, (1, 1, 1))):
c.arc(70, 64, r, -0.8, 0.8)
c.set_line_width(w)
c.set_source_rgb(*col)
c.stroke()
def mouse(c):
rrect(c, 32, 14, 64, 100, 32)
fill_stroke(c, lin(32, 0, 96, 0, "#ffffff", "#cbd5e1"))
c.move_to(64, 16)
c.line_to(64, 52)
c.move_to(34, 52)
c.line_to(94, 52)
c.set_source_rgb(*INK)
c.set_line_width(5)
c.stroke()
rrect(c, 59, 28, 10, 18, 5)
c.set_source_rgb(*rgb("#38a8f5"))
c.fill()
def wrench(c):
c.save()
c.translate(64, 64)
c.rotate(-math.pi / 4)
rrect(c, -11, -6, 22, 66, 11)
c.restore()
fill_stroke(c, lin(0, 0, 128, 128, "#e2e8f0", "#7b8796"))
cx, cy, r, d = 46, 46, 30, -3 * math.pi / 4
def u(a, k):
return cx + k * math.cos(a), cy + k * math.sin(a)
c.new_sub_path()
c.arc(cx, cy, r, d + 0.5, d - 0.5 + 2 * math.pi)
c.line_to(*u(d - 0.75, 12))
c.line_to(*u(d + 0.75, 12))
c.close_path()
fill_stroke(c, rad(cx, cy, r + 2, "#f1f5f9", "#94a3b8"))
def star(c):
polygon(c, star_pts(64, 68, 58, 26))
fill_stroke(c, lin(0, 10, 0, 120, "#fff6a8", "#ffd21f", "#ff9f0a"))
polygon(c, star_pts(56, 56, 16, 7))
c.set_source_rgba(1, 1, 1, 0.55)
c.fill()
def sparkle(c):
# 테두리 없는 반짝이(흰색, 버튼·카드 위 장식)
pts = star_pts(64, 64, 60, 12, n=4)
polygon(c, pts)
g = cairo.RadialGradient(64, 64, 4, 64, 64, 60)
g.add_color_stop_rgba(0, 1, 1, 1, 1)
g.add_color_stop_rgba(1, 1, 1, 0.85, 0.9)
c.set_source(g)
c.fill()
def rays(c):
# 햇살(흰색, 테두리 없음). 2배·부스트 버튼 뒤에서 천천히 돕니다.
g = cairo.RadialGradient(64, 64, 6, 64, 64, 64)
g.add_color_stop_rgba(0, 1, 1, 1, 1)
g.add_color_stop_rgba(0.6, 1, 1, 1, 0.55)
g.add_color_stop_rgba(1, 1, 1, 1, 0)
for i in range(12):
a0 = i * math.pi / 6
a1 = a0 + math.pi / 12
c.move_to(64, 64)
c.line_to(64 + 90 * math.cos(a0), 64 + 90 * math.sin(a0))
c.line_to(64 + 90 * math.cos(a1), 64 + 90 * math.sin(a1))
c.close_path()
c.set_source(g)
c.fill()
def glow(c):
# 둥근 빛(흰색). 버튼 뒤 후광·알림 빛
g = cairo.RadialGradient(64, 64, 0, 64, 64, 64)
g.add_color_stop_rgba(0, 1, 1, 1, 1)
g.add_color_stop_rgba(0.45, 1, 1, 1, 0.6)
g.add_color_stop_rgba(1, 1, 1, 1, 0)
c.rectangle(0, 0, 128, 128)
c.set_source(g)
c.fill()
def arrow_down(c):
polygon(c, [(40, 8), (88, 8), (88, 64), (114, 64), (64, 120), (14, 64), (40, 64)])
fill_stroke(c, lin(0, 8, 0, 120, "#fff6a8", "#ffd21f", "#ff8a0a"))
c.rectangle(48, 16, 10, 44)
c.set_source_rgba(1, 1, 1, 0.55)
c.fill()
def scroll(c):
# 업그레이드 목록(두루마리 메뉴판)
rrect(c, 24, 14, 80, 100, 10)
fill_stroke(c, lin(0, 14, 0, 114, "#fff8e6", "#f2d7a8"))
for y in (38, 58, 78):
c.arc(40, y, 6, 0, 2 * math.pi)
c.set_source_rgb(*rgb("#e8341c"))
c.fill()
rrect(c, 52, y - 4, 38, 8, 4)
c.set_source_rgba(*INK, 0.55)
c.fill()
rrect(c, 16, 98, 96, 22, 11)
fill_stroke(c, lin(0, 98, 0, 120, "#ff8a5a", "#d92f1c"), 6)
def hand(c):
# 누르는 손가락(튜토리얼)
c.move_to(50, 18)
c.curve_to(50, 6, 70, 6, 70, 18)
c.line_to(70, 56)
c.curve_to(92, 52, 110, 58, 110, 76)
c.line_to(108, 98)
c.curve_to(106, 116, 90, 122, 72, 122)
c.curve_to(54, 122, 42, 114, 34, 100)
c.line_to(20, 76)
c.curve_to(14, 64, 30, 58, 38, 68)
c.line_to(50, 80)
c.close_path()
fill_stroke(c, lin(0, 6, 0, 122, "#ffe9d0", "#f5c89a"))
ICONS = [
("coin", coin), ("moneyBag", money_bag), ("bolt", bolt), ("gear", gear),
("upgrade", upgrade), ("plate", plate), ("lock", lock), ("check", check),
("close", close_x), ("table", table), ("sign", sign), ("flame", flame),
("sauce", sauce), ("chef", chef), ("store", store), ("tray", tray),
("Tteokbokki", tteokbokki), ("Gimbap", gimbap), ("Sundae", sundae), ("Eomuk", eomuk),
("Twigim", twigim), ("globe", globe), ("speaker", speaker), ("mouse", mouse),
("wrench", wrench), ("star", star), ("sparkle", sparkle), ("rays", rays),
("glow", glow), ("arrowDown", arrow_down), ("scroll", scroll), ("hand", hand),
]
def draw():
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, CELL * GRID, CELL * GRID)
for i, (name, fn) in enumerate(ICONS):
c = cairo.Context(surf)
c.translate((i % GRID) * CELL, (i // GRID) * CELL)
c.rectangle(0, 0, CELL, CELL)
c.clip()
# 테두리가 칸 밖으로 안 나가게 살짝 줄입니다.
c.translate(64, 64)
c.scale(0.9, 0.9)
c.translate(-64, -64)
fn(c)
return surf
def main(argv):
surf = draw()
if "--luau" in argv:
for i, (name, _) in enumerate(ICONS):
print(f"\t{name} = Vector2.new({(i % GRID) * CELL}, {(i // GRID) * CELL}),")
return
if "--sheet" in argv:
out = argv[argv.index("--sheet") + 1]
rows = (len(ICONS) + GRID - 1) // GRID
sheet = cairo.ImageSurface(cairo.FORMAT_ARGB32, CELL * GRID, (CELL + 20) * rows)
c = cairo.Context(sheet)
c.set_source_rgb(0.55, 0.75, 0.6)
c.paint()
for i, (name, _) in enumerate(ICONS):
x, y = (i % GRID) * CELL, (i // GRID) * (CELL + 20)
c.set_source_surface(surf, x - (i % GRID) * CELL + 0, y - (i // GRID) * CELL)
c.rectangle(x, y, CELL, CELL)
c.fill()
c.set_source_rgb(0, 0, 0)
c.move_to(x + 4, y + CELL + 15)
c.set_font_size(13)
c.show_text(name)
sheet.write_to_png(out)
print(out)
return
surf.write_to_png(OUT)
print(os.path.normpath(OUT))
if __name__ == "__main__":
main(sys.argv[1:])

20
bunsik-tycoon/tools/preview.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# 화면 UI 미리보기: 빌드 → 저장 버전 업로드 → 로블록스 서버에서 UI 덤프 → 그림(PNG)으로.
# tools/preview.sh 출력폴더
set -euo pipefail
cd "$(dirname "$0")/.."
export PATH="$HOME/.rokit/bin:$PATH"
out=${1:-.cache/preview}
mkdir -p .cache "$out"
rojo build default.project.json -o build/BunsikTycoon.rbxl >/dev/null
ver=$(python3 tools/cloud.py publish build/BunsikTycoon.rbxl | awk '{print $2}')
python3 tools/cloud.py run tests/cloud/dump_gui.luau --version "$ver" >.cache/dump_raw.txt || { tail -20 .cache/dump_raw.txt; exit 1; }
python3 - <<'PY'
import json
raw = open(".cache/dump_raw.txt").read()
line = [l for l in raw.splitlines() if l.startswith("output: ")][-1]
out = json.loads(line[len("output: "):])
data = out["results"][0]
open(".cache/gui_dump.json", "w").write(data)
PY
python3 tools/gui_render.py .cache/gui_dump.json "$out"