// Çizim: gökyüzü, tribün, pist, start kapısı, bitiş direği, at + jokey (yandan görünüm).
// Dünya: x metre cinsinden. Ekran x = wx * PPM - camPx.
export const W = 1080;
export const H = 1920;
export const PPM = 9; // metre başına piksel
export const LANES = 10;
export const laneY = (i) => 800 + i * 54;
export const laneScale = (i) => 0.74 + i * 0.032;
const RAIL_TOP = 748;
const RAIL_BOTTOM = 1338;
export const SILKS = [
{ c: '#e53935', c2: '#ffffff', p: 'plain' },
{ c: '#1e63d6', c2: '#fdd835', p: 'hoops' },
{ c: '#fdd835', c2: '#1a1a1a', p: 'sash' },
{ c: '#2e9d4a', c2: '#ffffff', p: 'hoops' },
{ c: '#f5f5f5', c2: '#d81b60', p: 'sash' },
{ c: '#222222', c2: '#ff9800', p: 'hoops' },
{ c: '#fb8c00', c2: '#1e63d6', p: 'plain' },
{ c: '#8e44ad', c2: '#ffffff', p: 'sash' },
{ c: '#ec407a', c2: '#222222', p: 'hoops' },
{ c: '#00acc1', c2: '#ffffff', p: 'plain' },
];
export const COATS = [
{ body: '#7a4524', mane: '#1c120c', name: 'doru' },
{ body: '#a0522d', mane: '#6b3418', name: 'al' },
{ body: '#2a2220', mane: '#0d0a09', name: 'yağız' },
{ body: '#a9a9a9', mane: '#5f5f5f', name: 'kır' },
{ body: '#4a2a18', mane: '#140c08', name: 'koyu doru' },
{ body: '#cf9f45', mane: '#f2e6c4', name: 'kula' },
];
function shade(hex, f) {
const n = parseInt(hex.slice(1), 16);
const r = Math.round(((n >> 16) & 255) * f);
const g = Math.round(((n >> 8) & 255) * f);
const b = Math.round((n & 255) * f);
return `rgb(${Math.min(255, r)},${Math.min(255, g)},${Math.min(255, b)})`;
}
function rng(seed) {
let s = seed >>> 0 || 1;
return () => ((s = (s * 1664525 + 1013904223) >>> 0) / 4294967296);
}
// ---------------- Sabit arka plan parçaları ----------------
function makeSky() {
const c = document.createElement('canvas');
c.width = W;
c.height = 760;
const g = c.getContext('2d');
const gr = g.createLinearGradient(0, 0, 0, 760);
gr.addColorStop(0, '#2f7fd6');
gr.addColorStop(0.55, '#7db8ee');
gr.addColorStop(1, '#cfe6f7');
g.fillStyle = gr;
g.fillRect(0, 0, W, 760);
// güneş parıltısı
const sun = g.createRadialGradient(860, 380, 10, 860, 380, 260);
sun.addColorStop(0, 'rgba(255,250,220,0.9)');
sun.addColorStop(1, 'rgba(255,250,220,0)');
g.fillStyle = sun;
g.fillRect(0, 0, W, 760);
return c;
}
function makeHills() {
const tw = 1600;
const c = document.createElement('canvas');
c.width = tw;
c.height = 260;
const g = c.getContext('2d');
const r = rng(7);
const layer = (col, base, amp, n) => {
g.fillStyle = col;
g.beginPath();
g.moveTo(0, 260);
const pts = [];
for (let i = 0; i <= n; i++) pts.push(base - r() * amp);
pts[n] = pts[0];
for (let i = 0; i <= n; i++) g.lineTo((i / n) * tw, pts[i]);
g.lineTo(tw, 260);
g.fill();
};
layer('#8fb7c9', 120, 90, 9);
layer('#6f9e6a', 190, 60, 12);
// ağaç sırası
for (let x = 0; x < tw; x += 26 + r() * 30) {
const h = 30 + r() * 30;
g.fillStyle = r() < 0.5 ? '#3f7a3f' : '#4b8a46';
g.beginPath();
g.ellipse(x, 230 - h / 2, 16 + r() * 8, h / 2 + 6, 0, 0, Math.PI * 2);
g.fill();
}
g.fillStyle = '#5c8f52';
g.fillRect(0, 228, tw, 32);
return c;
}
const STAND_W = 720;
function makeStand(seed) {
const c = document.createElement('canvas');
c.width = STAND_W;
c.height = 260;
const g = c.getContext('2d');
const r = rng(seed);
// çatı
g.fillStyle = '#e9edf2';
g.beginPath();
g.moveTo(0, 40);
g.lineTo(STAND_W, 40);
g.lineTo(STAND_W, 62);
g.lineTo(0, 62);
g.fill();
g.fillStyle = '#2e5d8a';
g.fillRect(0, 30, STAND_W, 12);
for (let x = 30; x < STAND_W; x += 120) {
g.fillStyle = '#c9d1da';
g.fillRect(x, 62, 8, 150);
}
// basamaklar
for (let row = 0; row < 7; row++) {
const y = 80 + row * 20;
g.fillStyle = row % 2 ? '#7c8794' : '#8b96a3';
g.fillRect(0, y, STAND_W, 20);
}
// seyirciler
const cols = ['#e53935', '#1e63d6', '#fdd835', '#ffffff', '#2e9d4a', '#fb8c00', '#8e44ad', '#222', '#ec407a', '#90a4ae'];
const skins = ['#f1c7a5', '#e0ac85', '#c98d63', '#a86f4c'];
for (let row = 0; row < 7; row++) {
const y = 80 + row * 20;
for (let x = 6 + r() * 6; x < STAND_W - 6; x += 11 + r() * 5) {
if (r() < 0.12) continue;
g.fillStyle = cols[Math.floor(r() * cols.length)];
g.fillRect(x - 4, y + 4, 9, 12);
g.fillStyle = skins[Math.floor(r() * skins.length)];
g.beginPath();
g.arc(x, y + 1, 4, 0, Math.PI * 2);
g.fill();
}
}
// ön duvar ve reklam panoları
g.fillStyle = '#1f4e79';
g.fillRect(0, 220, STAND_W, 40);
g.fillStyle = '#fff';
g.font = 'bold 22px system-ui, Arial';
g.textBaseline = 'middle';
const ads = ['HİPODROM', 'İYİ YARIŞLAR', 'KOŞU GÜNÜ', 'TRİBÜN'];
ads.forEach((t, i) => g.fillText(t, 30 + i * 180, 240));
return c;
}
function makeDirt() {
const tw = 512;
const c = document.createElement('canvas');
c.width = tw;
c.height = RAIL_BOTTOM - RAIL_TOP;
const g = c.getContext('2d');
const gr = g.createLinearGradient(0, 0, 0, c.height);
gr.addColorStop(0, '#b98a5e');
gr.addColorStop(1, '#a8754a');
g.fillStyle = gr;
g.fillRect(0, 0, tw, c.height);
const r = rng(11);
for (let i = 0; i < 900; i++) {
g.fillStyle = r() < 0.5 ? 'rgba(90,55,30,0.18)' : 'rgba(240,200,160,0.15)';
g.fillRect(r() * tw, r() * c.height, 2 + r() * 10, 1 + r() * 2);
}
return c;
}
export function createScene() {
return {
sky: makeSky(),
hills: makeHills(),
stands: [makeStand(3), makeStand(9), makeStand(21)],
dirt: makeDirt(),
dust: [],
};
}
const mod = (a, n) => ((a % n) + n) % n;
// ---------------- Arka plan ----------------
export function drawBackground(ctx, sc, camPx, t, excite) {
ctx.drawImage(sc.sky, 0, 0);
// bulutlar
ctx.fillStyle = 'rgba(255,255,255,0.85)';
for (let i = 0; i < 5; i++) {
const x = mod(i * 310 - camPx * 0.04 - t * 6, W + 400) - 200;
const y = 360 + (i % 3) * 50;
for (let k = 0; k < 4; k++) {
ctx.beginPath();
ctx.ellipse(x + k * 38, y - (k % 2) * 14, 44, 22, 0, 0, Math.PI * 2);
ctx.fill();
}
}
// tepeler
const hx = -mod(camPx * 0.15, 1600);
ctx.drawImage(sc.hills, hx, 450);
ctx.drawImage(sc.hills, hx + 1600, 450);
// tribün
const sp = camPx * 0.45;
const first = Math.floor(sp / STAND_W);
for (let k = first; k * STAND_W - sp < W; k++) {
const img = sc.stands[mod(k, 3)];
const x = k * STAND_W - sp;
const bob = excite > 0.05 ? Math.abs(Math.sin(t * 9 + k)) * 3 * excite : 0;
ctx.drawImage(img, x, 466 - bob);
}
}
export function drawTrack(ctx, sc, camPx, L) {
// dış korkuluk arkası çim şerit
ctx.fillStyle = '#4f8f45';
ctx.fillRect(0, 735, W, 15);
// toprak
const dx = -mod(camPx, 512);
for (let x = dx; x < W; x += 512) ctx.drawImage(sc.dirt, x, RAIL_TOP);
// kulvar izleri
ctx.strokeStyle = 'rgba(80,50,25,0.12)';
ctx.lineWidth = 2;
for (let i = 0; i < LANES; i++) {
ctx.beginPath();
ctx.moveTo(0, laneY(i) + 4);
ctx.lineTo(W, laneY(i) + 4);
ctx.stroke();
}
// iç saha çimi
const gy = RAIL_BOTTOM + 8;
ctx.fillStyle = '#3f8c3f';
ctx.fillRect(0, gy, W, H - gy);
ctx.fillStyle = 'rgba(255,255,255,0.05)';
const st = 160;
for (let x = -mod(camPx, st * 2); x < W; x += st * 2) ctx.fillRect(x, gy, st, H - gy);
// start çizgisi ve bitiş direği, mesafe direkleri
const sx = (wx) => wx * PPM - camPx;
for (const d of [400, 200, 100]) {
const x = sx(L - d);
if (x < -60 || x > W + 60) continue;
pole(ctx, x, RAIL_TOP - 8, d === 100 ? '#e53935' : d === 200 ? '#1e63d6' : '#2e9d4a', String(d));
}
const fx = sx(L);
if (fx > -80 && fx < W + 80) {
// bitiş çizgisi
ctx.fillStyle = 'rgba(255,255,255,0.9)';
ctx.fillRect(fx - 3, RAIL_TOP, 6, RAIL_BOTTOM - RAIL_TOP);
ctx.fillStyle = '#e53935';
ctx.fillRect(fx - 7, RAIL_TOP, 3, RAIL_BOTTOM - RAIL_TOP);
// direk
ctx.fillStyle = '#ffffff';
ctx.fillRect(fx - 5, RAIL_TOP - 170, 10, 170);
ctx.beginPath();
ctx.arc(fx, RAIL_TOP - 190, 34, 0, Math.PI * 2);
ctx.fillStyle = '#e53935';
ctx.fill();
ctx.lineWidth = 6;
ctx.strokeStyle = '#fff';
ctx.stroke();
ctx.fillStyle = '#fff';
ctx.font = '900 20px system-ui, Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText('FİNİŞ', fx, RAIL_TOP - 190);
}
// korkuluklar
rail(ctx, camPx, RAIL_TOP - 4);
}
function pole(ctx, x, y, col, label) {
ctx.fillStyle = '#fff';
ctx.fillRect(x - 4, y - 120, 8, 120);
ctx.fillStyle = col;
ctx.beginPath();
ctx.arc(x, y - 132, 24, 0, Math.PI * 2);
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = '#fff';
ctx.stroke();
ctx.fillStyle = '#fff';
ctx.font = '900 18px system-ui, Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(label, x, y - 132);
}
function rail(ctx, camPx, y) {
ctx.fillStyle = '#f4f4f4';
ctx.fillRect(0, y - 26, W, 7);
const step = 90;
for (let x = -mod(camPx, step); x < W; x += step) ctx.fillRect(x - 3, y - 26, 6, 30);
}
export function drawInnerRail(ctx, camPx) {
const y = RAIL_BOTTOM + 12;
ctx.fillStyle = 'rgba(0,0,0,0.18)';
ctx.fillRect(0, y + 6, W, 6);
ctx.fillStyle = '#f4f4f4';
ctx.fillRect(0, y - 26, W, 8);
const step = 90;
for (let x = -mod(camPx, step); x < W; x += step) ctx.fillRect(x - 3, y - 26, 6, 32);
}
// start kapısı: arka parça atlardan önce, ön parça sonra çizilir
export function drawGate(ctx, camPx, open, front) {
const x = 0 * PPM - camPx + 26;
if (x < -300 || x > W + 300) return;
for (let i = 0; i < LANES; i++) {
const y = laneY(i);
const s = laneScale(i);
const h = 175 * s;
if (!front) {
ctx.fillStyle = 'rgba(30,90,50,0.9)';
ctx.fillRect(x - 210 * s, y - h, 8 * s, h);
continue;
}
// ön kapı (açılınca yana döner)
ctx.fillStyle = '#1f6b3a';
ctx.fillRect(x - 4 * s, y - h, 10 * s, h);
const dw = 34 * s * (1 - open);
if (dw > 1) {
ctx.fillStyle = '#2e9d4a';
ctx.fillRect(x + 6 * s, y - h * 0.75, dw, h * 0.55);
ctx.strokeStyle = '#d8f5df';
ctx.lineWidth = 2;
ctx.strokeRect(x + 6 * s, y - h * 0.75, dw, h * 0.55);
}
ctx.fillStyle = '#fff';
ctx.font = `900 ${Math.round(18 * s)}px system-ui, Arial`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(String(i + 1), x + 1, y - h - 10 * s);
}
if (front) {
ctx.fillStyle = '#1f6b3a';
ctx.fillRect(x - 220, laneY(0) - 190, 240, 14);
}
}
// ---------------- At + jokey ----------------
function limb(ctx, x, y, a1, l1, a2, l2, w, col) {
const kx = x + Math.sin(a1) * l1;
const ky = y + Math.cos(a1) * l1;
const fx = kx + Math.sin(a2) * l2;
const fy = ky + Math.cos(a2) * l2;
ctx.strokeStyle = col;
ctx.lineCap = 'round';
ctx.lineWidth = w;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(kx, ky);
ctx.stroke();
ctx.lineWidth = w * 0.62;
ctx.beginPath();
ctx.moveTo(kx, ky);
ctx.lineTo(fx, fy);
ctx.stroke();
ctx.fillStyle = '#1b1410';
ctx.beginPath();
ctx.ellipse(fx + 2, fy + 1, 5.5, 4, a2, 0, Math.PI * 2);
ctx.fill();
}
// rotary gallop: arka yakın, arka uzak, ön uzak, ön yakın
const LEG = { hn: 0.0, hf: 0.08, ff: 0.38, fn: 0.48 };
function legAngles(front, p, off, moving) {
if (!moving) return front ? [0.02, 0.02] : [0.06, -0.04];
const ph = (p + off) * Math.PI * 2;
const th = (front ? 0.62 : 0.5) * Math.sin(ph) + (front ? 0.05 : -0.05);
const fold = Math.max(0, Math.cos(ph));
return front ? [th, th - 1.3 * fold] : [th, th - 0.35 - 0.9 * fold];
}
// Atı çizer. (x,y): atın burnunun yere izdüşümü. s: ölçek.
export function drawHorse(ctx, x, y, s, h, t) {
const coat = COATS[h.coat];
const silk = SILKS[h.silk];
const p = h.gait;
const moving = h.moving;
const bob = moving ? (1 - Math.cos(p * Math.PI * 4)) * 2.6 : Math.sin(t * 1.5 + h.seed) * 0.6;
const pitch = moving ? Math.sin(p * Math.PI * 2) * 0.035 : 0;
const headNod = moving ? Math.sin(p * Math.PI * 2 + 1.2) * 0.07 : Math.sin(t * 0.9 + h.seed) * 0.04;
ctx.save();
ctx.translate(x - 112 * s, y);
ctx.scale(s, s);
// gölge
ctx.fillStyle = 'rgba(60,35,15,0.28)';
ctx.beginPath();
ctx.ellipse(0, 2, 82, 9, 0, 0, Math.PI * 2);
ctx.fill();
ctx.translate(0, -bob);
ctx.rotate(pitch);
const far = shade(coat.body, 0.7);
const legW = 13;
// uzak bacaklar
{
const [a, b] = legAngles(false, p, LEG.hf, moving);
limb(ctx, -44, -84, a, 40, b, 42, legW, far);
const [c, d] = legAngles(true, p, LEG.ff, moving);
limb(ctx, 40, -82, c, 40, d, 42, legW, far);
}
// kuyruk
const sw = moving ? Math.sin(p * Math.PI * 2) * 8 : Math.sin(t * 2 + h.seed) * 5;
ctx.strokeStyle = coat.mane;
ctx.lineWidth = 11;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(-66, -112);
ctx.quadraticCurveTo(-92, -112 + sw * 0.4, moving ? -112 : -84, (moving ? -92 : -66) + sw);
ctx.stroke();
// gövde
ctx.fillStyle = coat.body;
ctx.beginPath();
ctx.ellipse(0, -98, 60, 24, 0, 0, Math.PI * 2);
ctx.ellipse(40, -100, 25, 27, 0, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.ellipse(-42, -103, 29, 27, 0, 0, Math.PI * 2);
ctx.fill();
// boyun + baş
ctx.save();
ctx.translate(46, -110);
ctx.rotate(headNod + (moving ? 0.18 : 0));
ctx.fillStyle = coat.body;
ctx.beginPath();
ctx.moveTo(-18, -8);
ctx.lineTo(24, -52);
ctx.lineTo(40, -42);
ctx.lineTo(18, 22);
ctx.closePath();
ctx.fill();
// baş
ctx.beginPath();
ctx.moveTo(22, -56);
ctx.quadraticCurveTo(36, -62, 70, -26);
ctx.quadraticCurveTo(74, -16, 64, -14);
ctx.quadraticCurveTo(44, -22, 30, -30);
ctx.closePath();
ctx.fill();
// kulak
ctx.beginPath();
ctx.moveTo(22, -54);
ctx.lineTo(22, -70);
ctx.lineTo(31, -56);
ctx.fill();
// göz, burun
ctx.fillStyle = '#0d0a09';
ctx.beginPath();
ctx.arc(36, -44, 2.6, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.arc(66, -20, 2, 0, Math.PI * 2);
ctx.fill();
// yele
ctx.strokeStyle = coat.mane;
ctx.lineWidth = 6;
ctx.beginPath();
ctx.moveTo(-16, -12);
for (let k = 0; k <= 5; k++) {
const u = k / 5;
ctx.lineTo(-16 + u * 40 - (moving ? 6 : 2), -12 - u * 42 + Math.sin(t * 12 + k) * (moving ? 2.5 : 0.5));
}
ctx.stroke();
// dizgin
ctx.strokeStyle = '#3a2414';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(62, -18);
ctx.lineTo(28, -32);
ctx.stroke();
ctx.restore();
// yakın bacaklar
{
const [a, b] = legAngles(false, p, LEG.hn, moving);
limb(ctx, -40, -84, a, 40, b, 42, legW, coat.body);
const [c, d] = legAngles(true, p, LEG.fn, moving);
limb(ctx, 44, -82, c, 40, d, 42, legW, coat.body);
}
// eyer örtüsü + numara
ctx.fillStyle = silk.c;
ctx.fillRect(-20, -124, 36, 26);
ctx.strokeStyle = 'rgba(0,0,0,0.25)';
ctx.lineWidth = 2;
ctx.strokeRect(-20, -124, 36, 26);
ctx.fillStyle = isLight(silk.c) ? '#111' : '#fff';
ctx.font = '900 18px system-ui, Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(String(h.num), -2, -110);
// jokey
const pump = moving ? Math.sin(p * Math.PI * 2) * 5 : 0;
const lean = moving ? 1 : 0.4;
const hip = [0, -128];
const sh = [16 + 16 * lean, -156 + 8 * lean];
// bacak
ctx.strokeStyle = '#f2f2f2';
ctx.lineWidth = 9;
ctx.beginPath();
ctx.moveTo(hip[0], hip[1]);
ctx.lineTo(20, -124);
ctx.lineTo(10, -106);
ctx.stroke();
ctx.fillStyle = '#1b1410';
ctx.fillRect(4, -108, 12, 6);
// gövde
ctx.strokeStyle = silk.c;
ctx.lineWidth = 17;
ctx.beginPath();
ctx.moveTo(hip[0], hip[1]);
ctx.lineTo(sh[0], sh[1]);
ctx.stroke();
if (silk.p !== 'plain') {
ctx.strokeStyle = silk.c2;
ctx.lineWidth = 5;
ctx.beginPath();
if (silk.p === 'hoops') {
const m = [(hip[0] + sh[0]) / 2, (hip[1] + sh[1]) / 2];
ctx.moveTo(m[0] - 6, m[1] - 7);
ctx.lineTo(m[0] + 6, m[1] + 7);
} else {
ctx.moveTo(hip[0] + 4, hip[1] - 2);
ctx.lineTo(sh[0] - 2, sh[1] + 6);
}
ctx.stroke();
}
// kol
ctx.strokeStyle = silk.c;
ctx.lineWidth = 7;
ctx.beginPath();
ctx.moveTo(sh[0], sh[1]);
ctx.lineTo(sh[0] + 12, sh[1] + 12 + pump * 0.4);
ctx.lineTo(sh[0] + 26 + pump, sh[1] + 16);
ctx.stroke();
ctx.fillStyle = '#f1c7a5';
ctx.beginPath();
ctx.arc(sh[0] + 26 + pump, sh[1] + 16, 3.5, 0, Math.PI * 2);
ctx.fill();
// baş + kask
const hx = sh[0] + 9;
const hy = sh[1] - 10;
ctx.fillStyle = '#f1c7a5';
ctx.beginPath();
ctx.arc(hx + 2, hy + 2, 7, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = silk.c2 === '#ffffff' && silk.p === 'plain' ? silk.c : silk.c2;
ctx.beginPath();
ctx.arc(hx, hy - 1, 8.5, Math.PI, Math.PI * 2);
ctx.fill();
ctx.fillRect(hx, hy - 2, 13, 3);
ctx.restore();
}
function isLight(hex) {
const n = parseInt(hex.slice(1), 16);
return ((n >> 16) & 255) * 0.3 + ((n >> 8) & 255) * 0.59 + (n & 255) * 0.11 > 170;
}
// toz parçacıkları
export function addDust(sc, wxPx, y, s, n = 1) {
for (let i = 0; i < n; i++) {
if (sc.dust.length > 400) sc.dust.shift();
sc.dust.push({ x: wxPx - 150 * s + Math.random() * 40 * s, y: y - Math.random() * 6, vx: -40 - Math.random() * 60, vy: -20 - Math.random() * 30, r: (4 + Math.random() * 7) * s, life: 0, max: 0.6 + Math.random() * 0.5 });
}
}
export function drawDust(ctx, sc, camPx, dt) {
for (let i = sc.dust.length - 1; i >= 0; i--) {
const d = sc.dust[i];
d.life += dt;
if (d.life > d.max) {
sc.dust.splice(i, 1);
continue;
}
d.x += d.vx * dt;
d.y += d.vy * dt;
d.vy += 30 * dt;
const a = 0.35 * (1 - d.life / d.max);
ctx.fillStyle = `rgba(190,150,110,${a})`;
ctx.beginPath();
ctx.arc(d.x - camPx, d.y, d.r * (1 + d.life), 0, Math.PI * 2);
ctx.fill();
}
}
// isim etiketi + yorum balonu (ekran koordinatı)
export function drawLabel(ctx, x, y, s, h, t) {
const silk = SILKS[h.silk];
const fs = Math.round(17 + 7 * s);
ctx.font = `800 ${fs}px system-ui, -apple-system, 'Segoe UI', Arial`;
const name = h.bot ? h.name : '@' + h.name;
const text = name.length > 16 ? name.slice(0, 15) + '…' : name;
const tw = ctx.measureText(text).width;
const nw = fs + 6;
const pw = tw + nw + 18;
const lx = x - 70 * s - pw / 2;
const ly = y - 215 * s;
ctx.globalAlpha = h.finishedPlace ? 0.85 : 1;
roundRect(ctx, lx, ly - fs * 0.75, pw, fs * 1.5, fs * 0.75);
ctx.fillStyle = h.bot ? 'rgba(20,30,40,0.55)' : 'rgba(10,15,25,0.78)';
ctx.fill();
ctx.fillStyle = silk.c;
ctx.beginPath();
ctx.arc(lx + nw / 2 + 4, ly, nw / 2 - 2, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = isLight(silk.c) ? '#111' : '#fff';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = `900 ${Math.round(fs * 0.8)}px system-ui, Arial`;
ctx.fillText(String(h.num), lx + nw / 2 + 4, ly + 1);
ctx.font = `800 ${fs}px system-ui, -apple-system, 'Segoe UI', Arial`;
ctx.fillStyle = '#fff';
ctx.textAlign = 'left';
ctx.fillText(text, lx + nw + 8, ly + 1);
// hız efekti
if (h.boost > 1.2 && h.moving) {
ctx.strokeStyle = `rgba(255,255,255,${Math.min(0.6, (h.boost - 1) * 0.25)})`;
ctx.lineWidth = 3;
for (let k = 0; k < 4; k++) {
const yy = y - (40 + k * 28) * s;
const xx = x - (230 + ((t * 900 + k * 70) % 120)) * s;
ctx.beginPath();
ctx.moveTo(xx, yy);
ctx.lineTo(xx - 60 * s, yy);
ctx.stroke();
}
}
// yorum balonu: ismin sağında
if (h.bubble && h.bubbleUntil > t) {
const a = Math.min(1, (h.bubbleUntil - t) * 3);
ctx.globalAlpha = a;
ctx.font = `700 ${Math.round(fs * 0.85)}px system-ui, Arial`;
const bt = h.bubble.length > 22 ? h.bubble.slice(0, 21) + '…' : h.bubble;
const bw = ctx.measureText(bt).width + 20;
const bh = fs * 1.3;
const bx = lx + pw + 8;
const by = ly - bh / 2;
roundRect(ctx, bx, by, bw, bh, bh / 2);
ctx.fillStyle = '#fff';
ctx.fill();
ctx.beginPath();
ctx.moveTo(bx + 2, ly - 5);
ctx.lineTo(bx - 7, ly);
ctx.lineTo(bx + 2, ly + 5);
ctx.fill();
ctx.fillStyle = '#111';
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
ctx.fillText(bt, bx + 10, ly + 1);
}
ctx.globalAlpha = 1;
}
export function roundRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
// pistin altında küçük yarış haritası
export function drawMiniMap(ctx, horses, L, x0, y0, w) {
roundRect(ctx, x0 - 20, y0 - 34, w + 40, 78, 18);
ctx.fillStyle = 'rgba(10,25,15,0.72)';
ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.3)';
ctx.fillRect(x0, y0 - 2, w, 4);
for (const d of [400, 200, 100]) {
ctx.fillStyle = 'rgba(255,255,255,0.5)';
ctx.fillRect(x0 + ((L - d) / L) * w - 1, y0 - 10, 2, 20);
}
ctx.fillStyle = '#e53935';
ctx.fillRect(x0 + w - 2, y0 - 16, 4, 32);
ctx.font = '700 15px system-ui, Arial';
ctx.fillStyle = 'rgba(255,255,255,0.75)';
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
ctx.fillText('START', x0, y0 - 20);
ctx.textAlign = 'right';
ctx.fillText('FİNİŞ', x0 + w, y0 - 20);
const sorted = [...horses].sort((a, b) => a.x - b.x);
for (const h of sorted) {
const silk = SILKS[h.silk];
const px = x0 + Math.min(1, Math.max(0, h.x / L)) * w;
ctx.beginPath();
ctx.arc(px, y0 + 14, 11, 0, Math.PI * 2);
ctx.fillStyle = silk.c;
ctx.fill();
ctx.lineWidth = 2;
ctx.strokeStyle = '#fff';
ctx.stroke();
ctx.fillStyle = isLight(silk.c) ? '#111' : '#fff';
ctx.textAlign = 'center';
ctx.font = '900 12px system-ui, Arial';
ctx.fillText(String(h.num), px, y0 + 15);
}
}
Lisans bilgisi projenin LICENSE dosyasında.