80 lines
3.3 KiB
TypeScript
80 lines
3.3 KiB
TypeScript
import { useId } from 'react'
|
|
import { moonPath } from '@nalssigak/shared/lib/today'
|
|
|
|
// 앞면 바다(어두운 무늬) 자리: [x, y, 가로 반지름, 세로 반지름]. 실제 달 앞면 배치를 대강 따른다
|
|
const MARIA: [number, number, number, number][] = [
|
|
[-0.32, -0.36, 0.3, 0.26],
|
|
[0.12, -0.36, 0.17, 0.15],
|
|
[0.3, -0.06, 0.2, 0.17],
|
|
[-0.56, 0.06, 0.26, 0.42],
|
|
[0.66, -0.26, 0.1, 0.12],
|
|
[0.52, 0.22, 0.13, 0.15],
|
|
[-0.14, 0.44, 0.18, 0.13],
|
|
[-0.46, 0.5, 0.1, 0.09],
|
|
]
|
|
// 작은 크레이터: [x, y, 반지름]
|
|
const CRATERS: [number, number, number][] = [
|
|
[0.1, 0.72, 0.07],
|
|
[0.42, 0.52, 0.05],
|
|
[-0.66, -0.5, 0.05],
|
|
[0.62, 0.52, 0.04],
|
|
[-0.2, 0.08, 0.04],
|
|
]
|
|
|
|
// 저녁(노을)엔 노을빛이 도는 달, 밤엔 하얀 달
|
|
const TONES = {
|
|
night: { body: ['#fffcf2', '#f6ebcb', '#e0cc98'], shade: '#1a2050' },
|
|
dusk: { body: ['#fff8ee', '#ffe2cc', '#f2b9a2'], shade: '#4a2a63' },
|
|
}
|
|
|
|
/** 오늘 밤 실제 모양대로 그린 달. pct 는 빛나는 면의 비율 0~100, 기우는 달은 왼쪽이 밝다 */
|
|
export function MoonArt({ pct, waxing, tone = 'night', className }: { pct: number; waxing: boolean; tone?: keyof typeof TONES; className?: string }) {
|
|
const id = useId()
|
|
const t = TONES[tone]
|
|
const k = pct / 100
|
|
const full = pct >= 99
|
|
const hidden = pct <= 1
|
|
return (
|
|
<svg viewBox="-1.5 -1.5 3 3" className={className} aria-hidden="true">
|
|
<defs>
|
|
<radialGradient id={`${id}glow`}>
|
|
<stop offset="0.6" stopColor="#fff4cf" stopOpacity="0.55" />
|
|
<stop offset="0.8" stopColor="#ffe9a8" stopOpacity="0.16" />
|
|
<stop offset="1" stopColor="#ffe9a8" stopOpacity="0" />
|
|
</radialGradient>
|
|
<radialGradient id={`${id}body`} cx="0.4" cy="0.36" r="0.72">
|
|
<stop offset="0" stopColor={t.body[0]} />
|
|
<stop offset="0.6" stopColor={t.body[1]} />
|
|
<stop offset="1" stopColor={t.body[2]} />
|
|
</radialGradient>
|
|
<radialGradient id={`${id}limb`}>
|
|
<stop offset="0.72" stopColor="#8a6f3c" stopOpacity="0" />
|
|
<stop offset="1" stopColor="#8a6f3c" stopOpacity="0.28" />
|
|
</radialGradient>
|
|
<clipPath id={`${id}disc`}>
|
|
<circle r="1" />
|
|
</clipPath>
|
|
<filter id={`${id}soft`} x="-0.2" y="-0.2" width="1.4" height="1.4">
|
|
<feGaussianBlur stdDeviation="0.035" />
|
|
</filter>
|
|
</defs>
|
|
{!hidden && <circle r="1.5" fill={`url(#${id}glow)`} opacity={full ? 1 : 0.12 + 0.8 * k} />}
|
|
<g clipPath={`url(#${id}disc)`}>
|
|
<circle r="1" fill={`url(#${id}body)`} />
|
|
<g filter={`url(#${id}soft)`} fill="#c4b287" opacity="0.55">
|
|
{MARIA.map(([x, y, rx, ry]) => (
|
|
<ellipse key={`${x},${y}`} cx={x} cy={y} rx={rx} ry={ry} />
|
|
))}
|
|
</g>
|
|
{CRATERS.map(([x, y, r]) => (
|
|
<circle key={`${x},${y}`} cx={x} cy={y} r={r} fill="#efe2bd" stroke="#cdbb8c" strokeWidth="0.018" opacity="0.8" />
|
|
))}
|
|
<circle r="1" fill={`url(#${id}limb)`} />
|
|
{/* 안 보이는 쪽: 흐릿한 경계로 덮고, 땅빛(지구조) 정도만 비치게 */}
|
|
{!full && <path d={moonPath(pct, 1.04, false)} fill={t.shade} opacity="0.94" filter={`url(#${id}soft)`} transform={waxing ? undefined : 'scale(-1,1)'} />}
|
|
</g>
|
|
{hidden && <circle r="1" fill="none" stroke="#fff" strokeOpacity="0.18" strokeWidth="0.025" />}
|
|
</svg>
|
|
)
|
|
}
|