|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useEffect, useMemo, useRef, useState } from 'react'; |
| 4 | +import { EASINGS, EASING_KEYS, SIGILS, type EasingKey } from '../easings'; |
| 5 | + |
| 6 | +const DURATION = 1800; |
| 7 | +const REST = 600; |
| 8 | + |
| 9 | +export default function CurveVisualizer() { |
| 10 | + const [selected, setSelected] = useState<EasingKey>('easeOutBack'); |
| 11 | + const [t, setT] = useState(0); |
| 12 | + const rafRef = useRef<number | null>(null); |
| 13 | + const startRef = useRef<number | null>(null); |
| 14 | + |
| 15 | + useEffect(() => { |
| 16 | + startRef.current = null; |
| 17 | + const tick = (now: number) => { |
| 18 | + if (startRef.current === null) startRef.current = now; |
| 19 | + const elapsed = (now - startRef.current) % (DURATION + REST); |
| 20 | + if (elapsed > DURATION) setT(1); |
| 21 | + else setT(elapsed / DURATION); |
| 22 | + rafRef.current = requestAnimationFrame(tick); |
| 23 | + }; |
| 24 | + rafRef.current = requestAnimationFrame(tick); |
| 25 | + return () => { |
| 26 | + if (rafRef.current !== null) cancelAnimationFrame(rafRef.current); |
| 27 | + }; |
| 28 | + }, [selected]); |
| 29 | + |
| 30 | + const easing = EASINGS[selected]; |
| 31 | + |
| 32 | + const W = 500; |
| 33 | + const H = 380; |
| 34 | + const PAD = 30; |
| 35 | + |
| 36 | + const path = useMemo(() => { |
| 37 | + const pts: string[] = []; |
| 38 | + for (let i = 0; i <= 100; i++) { |
| 39 | + const x = i / 100; |
| 40 | + const y = easing.fn(x); |
| 41 | + const px = PAD + x * (W - PAD * 2); |
| 42 | + const py = H - PAD - y * (H - PAD * 2); |
| 43 | + pts.push(`${px.toFixed(1)},${py.toFixed(1)}`); |
| 44 | + } |
| 45 | + return 'M ' + pts.join(' L '); |
| 46 | + }, [easing]); |
| 47 | + |
| 48 | + const curT = Math.min(1, t); |
| 49 | + const curY = easing.fn(curT); |
| 50 | + const dotX = PAD + curT * (W - PAD * 2); |
| 51 | + const dotY = H - PAD - curY * (H - PAD * 2); |
| 52 | + const orbPct = curY * 100; |
| 53 | + |
| 54 | + return ( |
| 55 | + <div className="chapter"> |
| 56 | + <div className="chapter-mark"> |
| 57 | + <span className="num">I</span> |
| 58 | + <span>CHAPTER ONE — 魔導書の基礎</span> |
| 59 | + </div> |
| 60 | + <h2 className="chapter-title">Easingとは、動きに「生命」を吹き込む魔法</h2> |
| 61 | + <p className="chapter-desc"> |
| 62 | + ゲーム内のあらゆる動き — キャラクターの歩み、放たれた矢の軌跡、宝箱の開く瞬間 — これらが単調に感じるかワクワクするかは、「時間に対して値がどう変化するか」で決まる。Easing関数はその変化の形を司る古の術である。 |
| 63 | + </p> |
| 64 | + |
| 65 | + <div className="graph-panel"> |
| 66 | + <div> |
| 67 | + <div className="graph-stage"> |
| 68 | + <svg className="graph-svg" viewBox={`0 0 ${W} ${H}`} preserveAspectRatio="xMidYMid meet"> |
| 69 | + <text x={PAD} y={H - 8} fontFamily="Cinzel" fontSize="11" fill="#c89b3c" opacity="0.7">TIME →</text> |
| 70 | + <text x={PAD - 22} y={PAD + 4} fontFamily="Cinzel" fontSize="11" fill="#c89b3c" opacity="0.7" transform={`rotate(-90 ${PAD - 22} ${PAD + 4})`}>VALUE →</text> |
| 71 | + |
| 72 | + <line x1={PAD} y1={H - PAD} x2={W - PAD} y2={PAD} stroke="rgba(200,150,42,0.25)" strokeWidth="1.5" strokeDasharray="4 4" /> |
| 73 | + <text x={W - PAD - 90} y={PAD + 18} fontFamily="Cinzel" fontSize="10" fill="rgba(200,150,42,0.5)" letterSpacing="2">LINEAR REF</text> |
| 74 | + |
| 75 | + <line x1={PAD} y1={H - PAD} x2={W - PAD} y2={H - PAD} stroke="#c89b3c" strokeWidth="1.5" opacity="0.6" /> |
| 76 | + <line x1={PAD} y1={H - PAD} x2={PAD} y2={PAD} stroke="#c89b3c" strokeWidth="1.5" opacity="0.6" /> |
| 77 | + |
| 78 | + <path d={path} fill="none" stroke={easing.color} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" style={{ filter: `drop-shadow(0 0 6px ${easing.color})` }} /> |
| 79 | + |
| 80 | + <line x1={dotX} y1={H - PAD} x2={dotX} y2={dotY} stroke={easing.color} strokeWidth="1" strokeDasharray="3 3" opacity="0.6" /> |
| 81 | + <line x1={PAD} y1={dotY} x2={dotX} y2={dotY} stroke={easing.color} strokeWidth="1" strokeDasharray="3 3" opacity="0.6" /> |
| 82 | + |
| 83 | + <circle cx={dotX} cy={dotY} r="10" fill={easing.color} style={{ filter: `drop-shadow(0 0 12px ${easing.color})` }} /> |
| 84 | + <circle cx={dotX} cy={dotY} r="4" fill="#fff" /> |
| 85 | + |
| 86 | + <text x={PAD - 5} y={H - PAD + 14} fontFamily="VT323" fontSize="14" fill="#8a8578" textAnchor="end">0</text> |
| 87 | + <text x={W - PAD + 5} y={H - PAD + 14} fontFamily="VT323" fontSize="14" fill="#8a8578">1</text> |
| 88 | + <text x={PAD - 8} y={PAD + 4} fontFamily="VT323" fontSize="14" fill="#8a8578" textAnchor="end">1</text> |
| 89 | + </svg> |
| 90 | + </div> |
| 91 | + |
| 92 | + <div |
| 93 | + style={{ |
| 94 | + marginTop: 16, |
| 95 | + background: '#1a1208', |
| 96 | + border: '2px solid var(--border-dark)', |
| 97 | + borderRadius: 4, |
| 98 | + padding: '20px 20px', |
| 99 | + position: 'relative', |
| 100 | + overflow: 'hidden', |
| 101 | + }} |
| 102 | + > |
| 103 | + <div style={{ position: 'absolute', top: 10, left: 20, fontFamily: 'Cinzel, serif', fontSize: 10, letterSpacing: '0.3em', color: 'var(--parchment-dark)', opacity: 0.7 }}> |
| 104 | + REAL-TIME DEMONSTRATION |
| 105 | + </div> |
| 106 | + <div |
| 107 | + style={{ |
| 108 | + position: 'relative', |
| 109 | + height: 40, |
| 110 | + marginTop: 18, |
| 111 | + background: 'repeating-linear-gradient(90deg, rgba(200,150,42,0.15) 0 4px, transparent 4px 12px)', |
| 112 | + borderTop: '1px solid rgba(200,150,42,0.3)', |
| 113 | + borderBottom: '1px solid rgba(200,150,42,0.3)', |
| 114 | + }} |
| 115 | + > |
| 116 | + <div |
| 117 | + style={{ |
| 118 | + position: 'absolute', |
| 119 | + top: '50%', |
| 120 | + left: `calc(${orbPct}% - 16px)`, |
| 121 | + transform: 'translateY(-50%)', |
| 122 | + width: 32, |
| 123 | + height: 32, |
| 124 | + borderRadius: '50%', |
| 125 | + background: `radial-gradient(circle at 30% 30%, #fff, ${easing.color} 70%)`, |
| 126 | + boxShadow: `0 0 24px ${easing.color}, 0 0 8px ${easing.color}`, |
| 127 | + border: '1px solid rgba(255,255,255,0.4)', |
| 128 | + }} |
| 129 | + /> |
| 130 | + </div> |
| 131 | + <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 8, fontFamily: 'VT323, monospace', fontSize: 14, color: '#8a8578' }}> |
| 132 | + <span>◆ START</span> |
| 133 | + <span>t = {curT.toFixed(2)} value = {curY.toFixed(2)}</span> |
| 134 | + <span>GOAL ◆</span> |
| 135 | + </div> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | + |
| 139 | + <div className="spell-list"> |
| 140 | + <div style={{ fontFamily: 'Cinzel, serif', fontSize: 10, letterSpacing: '0.3em', color: 'var(--parchment-dark)', padding: '4px 4px 8px', opacity: 0.7 }}> |
| 141 | + ✦ SELECT A TECHNIQUE |
| 142 | + </div> |
| 143 | + {EASING_KEYS.map((k) => { |
| 144 | + const e = EASINGS[k]; |
| 145 | + const active = selected === k; |
| 146 | + return ( |
| 147 | + <button key={k} className={`spell-option ${active ? 'active' : ''}`} onClick={() => setSelected(k)} type="button"> |
| 148 | + <span className="spell-sigil" style={{ color: e.color, background: `${e.color}22` }}> |
| 149 | + {SIGILS[k]} |
| 150 | + </span> |
| 151 | + <span className="spell-names"> |
| 152 | + <div className="spell-rpg">{e.rpg}</div> |
| 153 | + <div className="spell-tech">{e.en}</div> |
| 154 | + </span> |
| 155 | + </button> |
| 156 | + ); |
| 157 | + })} |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + |
| 161 | + <div className="lore-plaque"> |
| 162 | + <span className="badge">◈ LORE</span> |
| 163 | + <span className="text"> |
| 164 | + <strong style={{ color: 'var(--gold-bright)' }}>『{easing.rpg}』</strong> |
| 165 | + ({easing.rpgEn}) ──── {easing.desc} |
| 166 | + </span> |
| 167 | + </div> |
| 168 | + </div> |
| 169 | + ); |
| 170 | +} |
0 commit comments