- 앱 하늘 장: 끝없이 흐르는 구름·해 광선·비/눈 (Compose 60fps), 1위·기온·비 칩 - 스킨 해 구슬 탭 → 하늘 장, 둘레 링 탭 → 그 각 상세 - 스킨은 시스템이 초당 10장 안팎이라 구름이 한 장에 1~2px 만 움직이게 30~60초에 한 번 가로지름 - 앱 상단 시계 11sp → 15sp (어르신도 잘 보이게) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
244 lines
15 KiB
Python
244 lines
15 KiB
Python
import json, math, os, sys
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
# 각 이름 → 아이콘. 시계 런타임이 점수 링 안의 작은 이미지를 그려 주지 않아, 이름을 보고 스킨에 넣은 아이콘을 고른다
|
|
GAK_ICONS = [(d["name"], d["icon"]) for d in json.load(open(os.path.join(HERE, "../../backend/seed/index_definition.json"), encoding="utf-8"))]
|
|
W = 450
|
|
CX, CY = 225, 235
|
|
ORB = 162
|
|
RING, RR = 68, 148
|
|
ANGLES = [210, 330, 150, 30, 180, 0]
|
|
APP = "kr.o2o.nalssigak"
|
|
INK, ORANGE, SHADE, CARD = "#FF28304A", "#FFFF7A45", "#FFD9E5F4", "#B8FFFFFF"
|
|
AMB0 = '<Variant mode="AMBIENT" target="alpha" value="0"/>'
|
|
|
|
MODES = { # 웹 .b-hero[data-t] 그라데이션, 시간대는 고정 시각 근사
|
|
"morning": ("[HOUR_0_23] >= 5 && [HOUR_0_23] < 11", "#FFFFD9B8 #FFFFE9D4 #FFDFF0FF", "0 0.4 1", INK),
|
|
"day": ("[HOUR_0_23] >= 11 && [HOUR_0_23] < 16", "#FF9FD3FF #FFCFE9FF #FFF1F8FF", "0 0.55 1", INK),
|
|
"evening": ("[HOUR_0_23] >= 16 && [HOUR_0_23] < 21", "#FF8E7CF0 #FFF28AA0 #FFFFC38A", "0 0.48 1", "#FFFFFFFF"),
|
|
}
|
|
NIGHT = ("#FF141B3D #FF27306A #FF3D3F86", "0 0.6 1", "#FFFFFFFF")
|
|
STARS = [(0.22, 0.20), (0.70, 0.14), (0.84, 0.40), (0.14, 0.52), (0.48, 0.10), (0.30, 0.78), (0.76, 0.70)]
|
|
|
|
def sky(colors, pos):
|
|
return f'''<PartDraw x="0" y="0" width="{W}" height="{W}">{AMB0}
|
|
<Rectangle x="0" y="0" width="{W}" height="{W}"><Fill color="#FFFFFFFF"><LinearGradient startX="0" startY="0" endX="0" endY="{W}" colors="{colors}" positions="{pos}"/></Fill></Rectangle>
|
|
</PartDraw>'''
|
|
|
|
def clock(color, ambient_visible=False):
|
|
alpha = "0" if ambient_visible else "255"
|
|
var = '<Variant mode="AMBIENT" target="alpha" value="255"/>' if ambient_visible else AMB0
|
|
return f'''<DigitalClock x="0" y="18" width="{W}" height="84">
|
|
<TimeText format="h:mm" hourFormat="SYNC_TO_DEVICE" align="CENTER" x="0" y="0" width="{W}" height="84" alpha="{alpha}">{var}
|
|
<Font family="bagel_fat_one" size="68" color="{color}"/>
|
|
</TimeText>
|
|
</DigitalClock>'''
|
|
|
|
def stars():
|
|
dots = "".join(f'<Ellipse x="{int(W*x)}" y="{int(W*y)}" width="5" height="5"><Fill color="#FFFFFFFF"/></Ellipse>' for x, y in STARS)
|
|
return f'<PartDraw x="0" y="0" width="{W}" height="{W}">{AMB0}{dots}</PartDraw>'
|
|
|
|
def cloud(y, w, h, period, phase, color="#FFFFFFFF"):
|
|
# 왼쪽 밖에서 들어와 오른쪽 밖으로 빠지고 다시 왼쪽에서 나온다 (끝없이 흐르는 하늘). period 초에 한 번 가로지른다.
|
|
# period 는 60 의 약수여야 분이 바뀔 때 튀지 않는다. 저전력 화면에서는 숨긴다
|
|
return f'''<PartDraw x="{-w}" y="{y - h}" width="{w}" height="{h * 2}">{AMB0}
|
|
<Ellipse x="{int(w * 0.2)}" y="0" width="{int(h * 1.6)}" height="{int(h * 1.6)}"><Fill color="{color}"/></Ellipse>
|
|
<RoundRectangle x="0" y="{h}" width="{w}" height="{h}" cornerRadiusX="{h // 2}" cornerRadiusY="{h // 2}"><Fill color="{color}"/></RoundRectangle>
|
|
<Transform target="x" value="{W + w} * fract([SECOND_MILLISECOND] / {period} + {phase}) - {w}"/>
|
|
</PartDraw>'''
|
|
|
|
# 구름 줄: 높이, 크기, 가로지르는 초, 시작 위상. 위상을 엇갈려 한쪽에서 빠질 때 다른 줄에서 새 구름이 들어온다
|
|
# 시간·날짜 아래로만 지나가게 (흰 글씨 위로 흰 구름이 지나면 안 보인다).
|
|
# 스킨은 시스템이 초당 10장 안팎으로만 그려서, 한 장에 1~2px 만 움직이도록 천천히 (빠른 하늘은 앱 첫 장에서 60장으로)
|
|
CLOUDS = [(160, 86, 30, 60, 0.0), (160, 64, 22, 60, 0.5), (345, 100, 32, 30, 0.45), (262, 64, 22, 30, 0.8)]
|
|
|
|
def orb_fill(colors):
|
|
blush = "" if colors == MOON else "".join(
|
|
f'<Ellipse x="{int(ORB * x - ORB * .08)}" y="{int(ORB * .62)}" width="{int(ORB * .16)}" height="{int(ORB * .09)}"><Fill color="#73FF7A8A"/></Ellipse>' for x in (0.2, 0.8))
|
|
return f'''<PartDraw x="{CX - ORB // 2}" y="{CY - ORB // 2}" width="{ORB}" height="{ORB}">{AMB0}
|
|
<Ellipse x="0" y="0" width="{ORB}" height="{ORB}"><Fill color="#FFFF8E4E"><RadialGradient centerX="{int(ORB * .34)}" centerY="{int(ORB * .30)}" radius="{int(ORB * .96)}" colors="{colors}" positions="0 0.3 0.68 1"/></Fill></Ellipse>
|
|
<Ellipse x="0" y="0" width="{ORB}" height="{ORB}"><Fill color="#00000000"><LinearGradient startX="{int(ORB * .45)}" startY="{int(ORB * .45)}" endX="{ORB}" endY="{ORB}" colors="#00AA3214 #57AA3214" positions="0 1"/></Fill></Ellipse>
|
|
{blush}
|
|
</PartDraw>'''
|
|
|
|
SUN = "#FFFFF5CF #FFFFC86E #FFFF8E4E #FFEE6436"
|
|
MOON = "#FFFFFFFF #FFD9D3FF #FFA99FEA #FF7F75CC"
|
|
|
|
def sun_rays():
|
|
"""구슬 둘레의 끝이 둥근 햇살 12개. 1분에 한 바퀴"""
|
|
size = int(ORB / 0.72)
|
|
c, r1, r2 = size / 2, size * 0.4, size * 0.462
|
|
lines = "".join(
|
|
f'<Line startX="{c + r1 * math.cos(math.radians(a)):.1f}" startY="{c + r1 * math.sin(math.radians(a)):.1f}" endX="{c + r2 * math.cos(math.radians(a)):.1f}" endY="{c + r2 * math.sin(math.radians(a)):.1f}"><Stroke thickness="{size * 0.044:.1f}" color="#FFFFB347" cap="ROUND"/></Line>'
|
|
for a in range(0, 360, 30))
|
|
return f'''<PartDraw x="{CX - size // 2}" y="{CY - size // 2}" width="{size}" height="{size}">{AMB0}
|
|
{lines}
|
|
<Transform target="angle" value="360 * fract([SECOND_MILLISECOND] / 60)"/>
|
|
</PartDraw>'''
|
|
|
|
def mode_block(colors, pos, ink, night=False):
|
|
parts = [sky(colors, pos)]
|
|
if night:
|
|
parts.append(stars())
|
|
cc = "#FFC9CDF0" if night else "#FFFFFFFF"
|
|
parts += [cloud(*c, color=cc) for c in CLOUDS] + [clock(ink), date_line(ink)]
|
|
return "\n ".join(parts)
|
|
|
|
def text(x, y, w, h, family, size, color, expr, amb=False):
|
|
return f'''<PartText x="{x}" y="{y}" width="{w}" height="{h}">{AMB0 if amb else ""}
|
|
<Text align="CENTER" ellipsis="TRUE"><Font family="{family}" size="{size}" color="{color}"><Template><![CDATA[%s]]><Parameter expression="{expr}"/></Template></Font></Text>
|
|
</PartText>'''
|
|
|
|
def orb_slot():
|
|
x, y = CX - ORB // 2, CY - ORB // 2
|
|
body = text(0, 30, ORB, 74, "bagel_fat_one", 58, "#FFFFFFFF", "[COMPLICATION.TEXT]") + text(14, 100, ORB - 28, 30, "jua", 21, "#FFFFFFFF", "[COMPLICATION.TITLE]")
|
|
return f'''<ComplicationSlot slotId="0" x="{x}" y="{y}" width="{ORB}" height="{ORB}" displayName="slot_rank1" supportedTypes="RANGED_VALUE SHORT_TEXT EMPTY" isCustomizable="TRUE">
|
|
<DefaultProviderPolicy defaultSystemProvider="EMPTY" defaultSystemProviderType="EMPTY" primaryProvider="{APP}/{APP}.Rank1ComplicationService" primaryProviderType="RANGED_VALUE"/>
|
|
<BoundingOval x="0" y="0" width="{ORB}" height="{ORB}"/>
|
|
<Complication type="RANGED_VALUE">
|
|
{body}
|
|
</Complication>
|
|
<Complication type="SHORT_TEXT">
|
|
{body}
|
|
</Complication>
|
|
<Complication type="EMPTY"/>
|
|
</ComplicationSlot>'''
|
|
|
|
PROGRESS = "clamp([COMPLICATION.RANGED_VALUE_VALUE], [COMPLICATION.RANGED_VALUE_MIN], [COMPLICATION.RANGED_VALUE_MAX]) / ([COMPLICATION.RANGED_VALUE_MAX] - [COMPLICATION.RANGED_VALUE_MIN]) * 360"
|
|
|
|
def icon_by_title(x, y, size):
|
|
exprs = "".join(f'<Expression name="i{n}"><![CDATA[[COMPLICATION.TITLE] == "{name}"]]></Expression>' for n, (name, _) in enumerate(GAK_ICONS))
|
|
cmps = "".join(f'<Compare expression="i{n}"><PartImage x="{x}" y="{y}" width="{size}" height="{size}">{AMB0}<Image resource="e_{icon}"/></PartImage></Compare>'
|
|
for n, (_, icon) in enumerate(GAK_ICONS))
|
|
return f"<Condition><Expressions>{exprs}</Expressions>{cmps}</Condition>"
|
|
|
|
def ring_slot(i, angle):
|
|
r = math.radians(angle)
|
|
x = int(CX + RR * math.cos(r) - RING / 2)
|
|
y = int(CY + RR * math.sin(r) - RING / 2)
|
|
s, a = RING, RING - 6
|
|
return f'''<ComplicationSlot slotId="{i + 1}" x="{x}" y="{y}" width="{s}" height="{s}" displayName="slot_ring" supportedTypes="RANGED_VALUE SHORT_TEXT EMPTY" isCustomizable="TRUE">
|
|
<DefaultProviderPolicy defaultSystemProvider="EMPTY" defaultSystemProviderType="EMPTY" primaryProvider="{APP}/{APP}.Rank{i + 2}ComplicationService" primaryProviderType="RANGED_VALUE"/>
|
|
<BoundingOval x="0" y="0" width="{s}" height="{s}"/>
|
|
<Complication type="RANGED_VALUE">
|
|
<PartDraw x="0" y="0" width="{s}" height="{s}">{AMB0}
|
|
<Ellipse x="0" y="0" width="{s}" height="{s}"><Fill color="{CARD}"/></Ellipse>
|
|
</PartDraw>
|
|
<PartDraw x="3" y="3" width="{a}" height="{a}">{AMB0}
|
|
<Arc centerX="{a / 2}" centerY="{a / 2}" width="{a}" height="{a}" startAngle="0" endAngle="360"><Stroke thickness="5" color="{SHADE}"/></Arc>
|
|
<Arc centerX="{a / 2}" centerY="{a / 2}" width="{a}" height="{a}" startAngle="0" endAngle="360"><Stroke thickness="5" color="{ORANGE}" cap="ROUND"/>
|
|
<Transform target="endAngle" value="{PROGRESS}"/>
|
|
</Arc>
|
|
</PartDraw>
|
|
{icon_by_title(s // 2 - 14, 9, 28)}
|
|
{text(0, 35, s, 24, "bagel_fat_one", 18, INK, "[COMPLICATION.TEXT]", amb=True)}
|
|
</Complication>
|
|
<Complication type="SHORT_TEXT">
|
|
<PartDraw x="0" y="0" width="{s}" height="{s}">{AMB0}
|
|
<Ellipse x="0" y="0" width="{s}" height="{s}"><Fill color="{CARD}"/></Ellipse>
|
|
</PartDraw>
|
|
{text(0, 22, s, 24, "bagel_fat_one", 18, INK, "[COMPLICATION.TEXT]", amb=True)}
|
|
</Complication>
|
|
<Complication type="EMPTY"/>
|
|
</ComplicationSlot>'''
|
|
|
|
# 기기 언어와 상관없이 한글 요일 ([DAY_OF_WEEK] 1 = 일요일)
|
|
WEEKDAY = " : ".join(f'[DAY_OF_WEEK] == {n + 1} ? "{d}"' for n, d in enumerate("일월화수목금")) + " : "토""
|
|
|
|
def chip(x, w, icon, expr):
|
|
return f'''<PartDraw x="{x}" y="364" width="{w}" height="40">{AMB0}
|
|
<RoundRectangle x="0" y="0" width="{w}" height="40" cornerRadiusX="20" cornerRadiusY="20"><Fill color="{CARD}"/></RoundRectangle>
|
|
<RoundRectangle x="0" y="35" width="{w}" height="5" cornerRadiusX="2" cornerRadiusY="2"><Fill color="#E6D9E5F4"/></RoundRectangle>
|
|
</PartDraw>
|
|
<PartImage x="{x + 8}" y="370" width="26" height="26">{AMB0}<Image resource="e_{icon}"/></PartImage>
|
|
{text(x + 32, 369, w - 38, 30, "jua", 21, INK, expr, amb=True)}'''
|
|
|
|
def precip_slot():
|
|
"""화면 전체를 덮는 숨은 칸. 날씨각 앱(RainComplicationService)이 글자 = 기온, 제목 = 비 소식을 주면
|
|
아래에 기온·비 칩을 그리고, 비 소식이 "비 와요"·"곧 비"면 빗줄기, "눈 와요"면 눈송이를 그린다.
|
|
터치는 막지 않게 BoundingOval 을 1px 로 둔다. 주기는 60 의 약수여야 분이 바뀔 때 튀지 않는다."""
|
|
import random
|
|
r = random.Random(7)
|
|
drops, flakes = [], []
|
|
for i in range(34):
|
|
x, ph = r.randint(0, W), r.random()
|
|
period = r.choice([1, 1.2, 1.5])
|
|
ln = r.randint(16, 26)
|
|
drops.append(f'''<PartDraw x="{x}" y="0" width="8" height="{ln + 2}">{AMB0}
|
|
<Line startX="7" startY="1" endX="2" endY="{ln}"><Stroke thickness="2.5" color="#CCEAF2FF" cap="ROUND"/></Line>
|
|
<Transform target="y" value="{W + 40} * fract([SECOND_MILLISECOND] / {period} + {ph:.2f}) - 30"/>
|
|
</PartDraw>''')
|
|
for i in range(26):
|
|
x, ph = r.randint(0, W), r.random()
|
|
period = r.choice([6, 10, 12])
|
|
d = r.randint(5, 10)
|
|
flakes.append(f'''<PartDraw x="{x}" y="0" width="{d}" height="{d}">{AMB0}
|
|
<Ellipse x="0" y="0" width="{d}" height="{d}"><Fill color="#E6FFFFFF"/></Ellipse>
|
|
<Transform target="y" value="{W + 30} * fract([SECOND_MILLISECOND] / {period} + {ph:.2f}) - 15"/>
|
|
<Transform target="x" value="{x} + 9 * sin(rad(360 * fract([SECOND_MILLISECOND] / 3 + {ph:.2f})))"/>
|
|
</PartDraw>''')
|
|
shade = lambda c: f'<PartDraw x="0" y="0" width="{W}" height="{W}">{AMB0}<Rectangle x="0" y="0" width="{W}" height="{W}"><Fill color="{c}"/></Rectangle></PartDraw>'
|
|
return f'''<ComplicationSlot slotId="7" x="0" y="0" width="{W}" height="{W}" displayName="slot_precip" supportedTypes="SHORT_TEXT EMPTY" isCustomizable="FALSE">
|
|
<DefaultProviderPolicy defaultSystemProvider="EMPTY" defaultSystemProviderType="EMPTY" primaryProvider="{APP}/{APP}.RainComplicationService" primaryProviderType="SHORT_TEXT"/>
|
|
<BoundingOval x="0" y="0" width="1" height="1"/>
|
|
<Complication type="SHORT_TEXT">
|
|
<Condition>
|
|
<Expressions>
|
|
<Expression name="rain"><![CDATA[[COMPLICATION.TITLE] == "비 와요" || [COMPLICATION.TITLE] == "곧 비"]]></Expression>
|
|
<Expression name="snow"><![CDATA[[COMPLICATION.TITLE] == "눈 와요"]]></Expression>
|
|
</Expressions>
|
|
<Compare expression="rain">
|
|
{shade("#66485A78")}
|
|
{"".join(drops)}
|
|
</Compare>
|
|
<Compare expression="snow">
|
|
{shade("#40A0AEC4")}
|
|
{"".join(flakes)}
|
|
</Compare>
|
|
</Condition>
|
|
{chip(108, 104, "thermo", "[COMPLICATION.TEXT]")}
|
|
{chip(220, 122, "umbrella", "[COMPLICATION.TITLE]")}
|
|
</Complication>
|
|
<Complication type="EMPTY"/>
|
|
</ComplicationSlot>'''
|
|
|
|
def date_line(ink):
|
|
return f'''<PartText x="0" y="92" width="{W}" height="30">{AMB0}
|
|
<Text align="CENTER"><Font family="jua" size="23" color="{ink}"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="{WEEKDAY}"/></Template></Font></Text>
|
|
</PartText>'''
|
|
|
|
exprs = "\n ".join(f'<Expression name="{k}"><![CDATA[{v[0].replace(">", ">").replace("<", "<").replace("&", "&")}]]></Expression>' for k, v in MODES.items())
|
|
compares = "\n ".join(f'<Compare expression="{k}">\n {mode_block(v[1], v[2], v[3])}\n </Compare>' for k, v in MODES.items())
|
|
|
|
xml = f'''<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- 날씨각 워치 스킨: 시간대 하늘, 해 구슬(1위), 둘레 링(2~7위), 아래 기온·비 칩. 링을 누르면 앱이 그 각 상세로 열린다. 점수는 날씨각 앱의 RankNComplicationService 가 공급한다.
|
|
직접 고치지 말고 watch/watchface/gen_watchface.py 를 고친 뒤 다시 만든다: python3 gen_watchface.py src/main/res/raw/watchface.xml -->
|
|
<WatchFace width="{W}" height="{W}">
|
|
<Metadata key="CLOCK_TYPE" value="DIGITAL"/>
|
|
<Metadata key="PREVIEW_TIME" value="11:52:00"/>
|
|
<Scene backgroundColor="#FF000000">
|
|
<!-- ponytail: 시간대는 고정 시각(5·11·16·21시)으로 근사. 일몰 기준으로 바꾸려면 앱이 공급하는 값으로 -->
|
|
<Condition>
|
|
<Expressions>
|
|
{exprs}
|
|
</Expressions>
|
|
{compares}
|
|
<Default>
|
|
{mode_block(NIGHT[0], NIGHT[1], NIGHT[2], night=True)}
|
|
</Default>
|
|
</Condition>
|
|
<!-- 주의: 칸(ComplicationSlot) 순서·slotId 를 바꿔 덮어 설치하면 기존 기기에서 공급원이 한 칸씩 밀린다 (에뮬레이터에서 확인). 새 칸은 맨 뒤에 붙인다 -->
|
|
{precip_slot()}
|
|
<!-- 해 구슬은 비 막 위에 (밤엔 달빛) -->
|
|
<Condition>
|
|
<Expressions><Expression name="night"><![CDATA[[HOUR_0_23] < 5 || [HOUR_0_23] >= 21]]></Expression></Expressions>
|
|
<Compare expression="night">{orb_fill(MOON)}</Compare>
|
|
<Default>{sun_rays()}{orb_fill(SUN)}</Default>
|
|
</Condition>
|
|
{clock("#FFFFFFFF", ambient_visible=True)}
|
|
{orb_slot()}
|
|
{"".join(ring_slot(i, a) for i, a in enumerate(ANGLES))}
|
|
</Scene>
|
|
</WatchFace>
|
|
'''
|
|
open(sys.argv[1], "w").write(xml)
|