267 lines
12 KiB
Python
267 lines
12 KiB
Python
"""연무장 허브 연출 그림 만들기(PD 2026-11-18 「연무장 화면에 애니메이션 연출 · 환경 연출」) → Assets/Resources/UI/Yeonmu/fx/
|
||
|
||
새로 그리는 것(작은 연출 부품 · 화풍 = 굵은 짙은 외곽선 + 단색 · 배경 구름은 외곽선 없는 부드러운 흰색):
|
||
z_0 · z_1 조는 병사 「z · Z」(게임 제목 글꼴 메이플스토리체 Bold · 연한 흰 바탕 + 남색 외곽선)
|
||
cloud_0 · 1 흘러가는 구름(배경 하늘 구름처럼 외곽선 없는 흰 구름 · 아래 연보라 그늘) · cloud_shadow_0 · 1 = 같은 모양을 흐린 땅 그림자
|
||
hay_0 · 1 말 입에서 떨어지는 건초 가닥
|
||
spark_dot 낮 화면 불똥(노랑 → 주황 단색 점 · 대련 · 망치)
|
||
arrow_bold 내정 화살 + 짙은 외곽선(작은 크기에서도 보이게)
|
||
배경에서 오려 내는 것(배경 그림 bg_yeonmu.png 그대로 · 화풍 동일):
|
||
flag_gate_l · r 성문 앞 깃발 천(펄럭임 = LobbyAmbient flag)
|
||
flag_gate_l · r _patch 그 깃발 자리를 주변 색으로 메운 바탕(흔들릴 때 원래 깃발이 비치지 않게 · 깃발 아래 고정)
|
||
게임에 이미 있는 그림을 복사(한 아틀라스 UI_Yeonmu = 연출 층 드로우콜 최소 · P41):
|
||
spark(타이틀 반짝이) · dust(타이틀 흙먼지) · glow · petal_0~2 · bird_0~1(로비) · grass_0~3(내정 연병장 풀꽃)
|
||
|
||
실행: <numpy 가 있는 python> -I Tools/yeonmu_fx.py (예 C:/ArtRnD/sprite_gen/repo/.venv/Scripts/python.exe) — 깃발 자리(FLAGS)는 배경 그림 px(1620×2400)
|
||
"""
|
||
import os
|
||
import shutil
|
||
|
||
import numpy as np
|
||
from PIL import Image, ImageDraw, ImageFilter, ImageFont
|
||
|
||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
A = os.path.join(ROOT, "Assets")
|
||
OUT = os.path.join(A, "Resources", "UI", "Yeonmu", "fx")
|
||
BG = os.path.join(A, "Resources", "UI", "Yeonmu", "bg_yeonmu.png")
|
||
FONT = os.path.join(A, "UI", "Fonts", "Maplestory OTF Bold.otf")
|
||
|
||
# 깃발 = 오려 낼 사각(배경 px · 천 위끝 = 가로대 바로 아래 · 아래끝 = 꼬리 끝 아래)
|
||
FLAGS = {
|
||
"flag_gate_l": (604, 796, 662, 884),
|
||
"flag_gate_r": (972, 796, 1030, 884),
|
||
}
|
||
|
||
COPIES = {
|
||
"spark": "Resources/UI/Title/pack/sparkle.png",
|
||
"dust": "Resources/UI/Title/pack/dust.png",
|
||
"glow": "UI/Lobby/anim/glow.png",
|
||
"petal_0": "UI/Lobby/anim/petal_0.png",
|
||
"petal_1": "UI/Lobby/anim/petal_1.png",
|
||
"petal_2": "UI/Lobby/anim/petal_2.png",
|
||
"bird_0": "UI/Lobby/anim/bird_0.png",
|
||
"bird_1": "UI/Lobby/anim/bird_1.png",
|
||
"grass_0": "UI/Domestic/anim/dom_grass_0.png",
|
||
"grass_1": "UI/Domestic/anim/dom_grass_1.png",
|
||
"grass_2": "UI/Domestic/anim/dom_grass_2.png",
|
||
"grass_3": "UI/Domestic/anim/dom_grass_3.png",
|
||
}
|
||
|
||
NAVY = (44, 51, 85, 255)
|
||
|
||
|
||
def save(im, name):
|
||
p = os.path.join(OUT, name + ".png")
|
||
im.save(p)
|
||
print("write", os.path.relpath(p, ROOT), im.size)
|
||
|
||
|
||
def z_glyph(ch, size):
|
||
"""글꼴 글자 하나 = 연한 흰 바탕 + 남색 외곽선(4배로 그려 줄임 · 외곽선 ≈ 3.5 px)."""
|
||
S = 4
|
||
font = ImageFont.truetype(FONT, int(size * 0.92 * S))
|
||
im = Image.new("RGBA", (size * S, size * S), (0, 0, 0, 0))
|
||
d = ImageDraw.Draw(im)
|
||
d.text((size * S // 2, size * S // 2), ch, font=font, fill=(240, 245, 255, 255), stroke_width=int(4.6 * S), stroke_fill=NAVY, anchor="mm")
|
||
im = im.crop(im.getbbox())
|
||
w, h = im.size
|
||
pad = 2 * S
|
||
c = Image.new("RGBA", (w + 2 * pad, h + 2 * pad), (0, 0, 0, 0))
|
||
c.paste(im, (pad, pad))
|
||
return c.resize(((w + 2 * pad) // S, (h + 2 * pad) // S), Image.LANCZOS)
|
||
|
||
|
||
def cloud(seed, w=512, h=208):
|
||
"""외곽선 없는 흰 뭉게구름(배경 하늘 구름 화풍) + 같은 모양의 흐린 그림자. 2배로 그려 줄임."""
|
||
rng = np.random.default_rng(seed)
|
||
S = 2
|
||
W, H = w * S, h * S
|
||
mask = Image.new("L", (W, H), 0)
|
||
d = ImageDraw.Draw(mask)
|
||
base = H * 0.78
|
||
# 밑단 = 납작한 타원 · 윗단 = 크기 다른 둥근 봉우리 4~5
|
||
d.ellipse([W * 0.06, base - H * 0.22, W * 0.94, base + H * 0.16], fill=255)
|
||
n = 5 if seed % 2 == 0 else 4
|
||
xs = np.linspace(0.2, 0.8, n) + rng.uniform(-0.04, 0.04, n)
|
||
for i, x in enumerate(xs):
|
||
r = H * (0.26 + 0.16 * np.sin(np.pi * (i + 0.5) / n) + rng.uniform(-0.03, 0.03))
|
||
cy = base - H * 0.14 - r * 0.55
|
||
d.ellipse([W * x - r, cy - r, W * x + r, cy + r], fill=255)
|
||
mask = mask.filter(ImageFilter.GaussianBlur(2.2 * S))
|
||
m = np.asarray(mask).astype(np.float32) / 255.0
|
||
yy = np.linspace(0, 1, H)[:, None]
|
||
# 위 = 흰색 · 아래 30 % = 연보라 그늘(배경 구름 아랫면 색 실측 근사)
|
||
top = np.array([255, 255, 255], np.float32)
|
||
low = np.array([214, 222, 242], np.float32)
|
||
t = np.clip((yy - 0.55) / 0.35, 0, 1)
|
||
rgb = top * (1 - t[..., None]) + low * t[..., None]
|
||
rgb = np.broadcast_to(rgb, (H, W, 3))
|
||
# 봉우리 안쪽 아래 그늘(마스크를 위로 밀어 겹치지 않는 아래 가장자리를 살짝 어둡게)
|
||
up = np.zeros_like(m)
|
||
sh = int(H * 0.06)
|
||
up[:-sh] = m[sh:]
|
||
rim = np.clip(m - up, 0, 1)[..., None]
|
||
rgb = rgb * (1 - 0.10 * rim) + low * 0.10 * rim
|
||
out = np.dstack([rgb, m * 255]).astype(np.uint8)
|
||
im = Image.fromarray(out, "RGBA").resize((w, h), Image.LANCZOS)
|
||
shadow = mask.filter(ImageFilter.GaussianBlur(14 * S)).resize((w, h), Image.LANCZOS)
|
||
sim = Image.merge("RGBA", [Image.new("L", (w, h), 255)] * 3 + [shadow])
|
||
return im, sim
|
||
|
||
|
||
def spark_dot(size=24):
|
||
"""낮 화면 불똥 = 속이 밝은 노랑 → 가장자리 주황 단색 점 + 얇은 진한 주황 테(밝은 모래·돌바닥 위에서도 보이게 · 빛 번짐 점 ember 는 밤 화면용이라 흐림)."""
|
||
S = 4
|
||
W = size * S
|
||
yy, xx = np.mgrid[0:W, 0:W].astype(np.float32)
|
||
c = (W - 1) / 2.0
|
||
d = np.sqrt((xx - c) ** 2 + (yy - c) ** 2) / (W * 0.5)
|
||
inner = np.array([255, 248, 200], np.float32)
|
||
outer = np.array([255, 150, 30], np.float32)
|
||
rim = np.array([214, 104, 16], np.float32)
|
||
t = np.clip(d / 0.8, 0, 1)[..., None]
|
||
rgb = inner * (1 - t) + outer * t
|
||
rgb = np.where((d > 0.8)[..., None], rim, rgb)
|
||
a = np.clip((1.0 - d) / 0.06, 0, 1) * 255
|
||
im = Image.fromarray(np.dstack([rgb, a]).astype(np.uint8), "RGBA")
|
||
return im.resize((size, size), Image.LANCZOS)
|
||
|
||
|
||
def hay(variant):
|
||
"""건초 가닥 = 노랑 + 짙은 갈색 외곽선(말 그림 건초와 같은 색 · 4배로 그려 줄임)."""
|
||
S = 8 # 44×24 로 그림(표시 ≈ 24 px · 작게 그려 키우면 흐림)
|
||
W, H = 22 * S, 12 * S
|
||
im = Image.new("RGBA", (W, H), (0, 0, 0, 0))
|
||
d = ImageDraw.Draw(im)
|
||
if variant == 0:
|
||
pts = [(3 * S, 8 * S), (11 * S, 5 * S), (19 * S, 4 * S)]
|
||
else:
|
||
pts = [(3 * S, 4 * S), (10 * S, 7 * S), (18 * S, 8 * S)]
|
||
d.line(pts, fill=(92, 56, 18, 255), width=int(4.8 * S), joint="curve")
|
||
for p in (pts[0], pts[-1]):
|
||
r = 2.4 * S
|
||
d.ellipse([p[0] - r, p[1] - r, p[0] + r, p[1] + r], fill=(92, 56, 18, 255))
|
||
d.line(pts, fill=(246, 198, 82, 255), width=int(2.2 * S), joint="curve")
|
||
return im.resize((W // 4, H // 4), Image.LANCZOS)
|
||
|
||
|
||
def arrow_bold(src, pad=8, ring=6):
|
||
"""내정 화살에 짙은 외곽선을 둘러 작은 크기(≈ 60 px)에서도 보이게(QA r1 「날아가는 화살 외곽선 없음」) — 원본 알파를 ring px 넓힌 자리를 짙은 갈색으로 깔고 위에 원본."""
|
||
im = Image.open(src).convert("RGBA")
|
||
w, h = im.size
|
||
c = Image.new("RGBA", (w + 2 * pad, h + 2 * pad), (0, 0, 0, 0))
|
||
c.paste(im, (pad, pad), im)
|
||
a = np.asarray(c)[..., 3] > 40
|
||
grown = dilate(a, ring)
|
||
back = np.zeros((c.height, c.width, 4), np.uint8)
|
||
back[grown] = (42, 30, 22, 255)
|
||
out = Image.fromarray(back, "RGBA").filter(ImageFilter.GaussianBlur(0.6))
|
||
out.alpha_composite(c)
|
||
return out
|
||
|
||
|
||
def dilate(m, n):
|
||
m = m.copy()
|
||
for _ in range(n):
|
||
d = m.copy()
|
||
d[1:] |= m[:-1]
|
||
d[:-1] |= m[1:]
|
||
d[:, 1:] |= m[:, :-1]
|
||
d[:, :-1] |= m[:, 1:]
|
||
m = d
|
||
return m
|
||
|
||
|
||
def component(m, seed):
|
||
"""m 안에서 seed(줄, 칸)와 4 방향으로 이어진 화소 · seed None = 사각 테두리의 m 화소 전부에서 시작."""
|
||
out = np.zeros_like(m)
|
||
if seed is None:
|
||
stack = [(y, x) for y in range(m.shape[0]) for x in (0, m.shape[1] - 1) if m[y, x]]
|
||
stack += [(y, x) for x in range(m.shape[1]) for y in (0, m.shape[0] - 1) if m[y, x]]
|
||
else:
|
||
stack = [seed] if m[seed] else []
|
||
while stack:
|
||
y, x = stack.pop()
|
||
if out[y, x] or not m[y, x]:
|
||
continue
|
||
out[y, x] = True
|
||
for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||
yy, xx = y + dy, x + dx
|
||
if 0 <= yy < m.shape[0] and 0 <= xx < m.shape[1] and not out[yy, xx] and m[yy, xx]:
|
||
stack.append((yy, xx))
|
||
return out
|
||
|
||
|
||
def flag_cut(bg, box):
|
||
"""깃발 천 = 빨강·노랑 칠 + 그 둘레 짙은 외곽선(빨강·노랑에서 4 px 안) · 구멍 메움. 바탕 = 천 자리를 주변 색 확산으로 메움."""
|
||
x0, y0, x1, y1 = box
|
||
a = np.asarray(bg.crop(box).convert("RGB")).astype(np.int32)
|
||
r, g, b = a[..., 0], a[..., 1], a[..., 2]
|
||
red = (r > 150) & (g < 120) & (b < 110) & (r - g > 60)
|
||
yel = (r > 200) & (g > 150) & (b < 150) & (r - b > 70)
|
||
core = red | yel
|
||
lum = 0.3 * r + 0.59 * g + 0.11 * b
|
||
dark = lum < 95
|
||
near = dilate(core, 3)
|
||
m = component(core | (near & dark), (core.shape[0] // 2, core.shape[1] // 2))
|
||
# 구멍 메움 = 바깥(사각 테두리)에서 닿지 않는 빈 곳만(꼬리 V 홈은 바깥과 이어져 그대로)
|
||
m = ~component(~m, None)
|
||
alpha = (m * 255).astype(np.uint8)
|
||
a_img = Image.fromarray(alpha, "L").filter(ImageFilter.GaussianBlur(0.6))
|
||
cloth = bg.crop(box).convert("RGBA")
|
||
cloth.putalpha(a_img)
|
||
# 바탕 메움 = 천(+2 px) 바깥 색을 안쪽으로 확산(가장 가까운 알려진 화소 평균 반복)
|
||
grow = dilate(m, 1)
|
||
pad = 6
|
||
big = np.asarray(bg.crop((x0 - pad, y0 - pad, x1 + pad, y1 + pad)).convert("RGB")).astype(np.float32)
|
||
unk = np.zeros(big.shape[:2], bool)
|
||
unk[pad:-pad, pad:-pad] = grow
|
||
known = ~unk
|
||
col = big.copy()
|
||
col[unk] = 0
|
||
for _ in range(400):
|
||
acc = np.zeros_like(col)
|
||
cnt = np.zeros(col.shape[:2], np.float32)
|
||
for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||
sh = np.roll(np.roll(col, dy, 0), dx, 1)
|
||
k = np.roll(np.roll(known, dy, 0), dx, 1)
|
||
acc += sh * k[..., None]
|
||
cnt += k
|
||
fill = unk & (cnt > 0)
|
||
col[fill] = acc[fill] / cnt[fill][..., None]
|
||
known = known | fill
|
||
if known.all():
|
||
break
|
||
patch = col[pad:-pad, pad:-pad]
|
||
pa = Image.fromarray((grow * 255).astype(np.uint8), "L").filter(ImageFilter.GaussianBlur(1.0))
|
||
pim = Image.fromarray(np.clip(patch, 0, 255).astype(np.uint8), "RGB").convert("RGBA")
|
||
pim.putalpha(pa)
|
||
return cloth, pim
|
||
|
||
|
||
def main():
|
||
os.makedirs(OUT, exist_ok=True)
|
||
save(z_glyph("z", 56), "z_0")
|
||
save(z_glyph("Z", 72), "z_1")
|
||
for i in range(2):
|
||
c, s = cloud(11 + i, 512, 208 if i == 0 else 176)
|
||
save(c, "cloud_%d" % i)
|
||
save(s, "cloud_shadow_%d" % i)
|
||
for i in range(2):
|
||
save(hay(i), "hay_%d" % i)
|
||
save(spark_dot(), "spark_dot")
|
||
save(arrow_bold(os.path.join(A, "UI/Domestic/anim/dom_arrow.png")), "arrow_bold")
|
||
bg = Image.open(BG).convert("RGBA")
|
||
for name, box in FLAGS.items():
|
||
cloth, patch = flag_cut(bg, box)
|
||
save(cloth, name)
|
||
save(patch, name + "_patch")
|
||
for name, src in COPIES.items():
|
||
dst = os.path.join(OUT, name + ".png")
|
||
shutil.copyfile(os.path.join(A, src), dst)
|
||
print("copy", src, "->", os.path.relpath(dst, ROOT))
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|