// MexicanTrainArt.js — baked canvas textures for "Sunday afternoon at the // kitchen table". All procedural: no image files. // // mt-room honey-oak plank table (grain, knots, seams, wear, a coffee // ring), a crocheted doily under the hub, and the props: a // coffee mug, a bowl of pretzels, the lemonade pitcher and a // glass, a sleeping tabby, the open wooden domino box // mt-vignette the warm light + vignette alone (over a chosen playfield) // mt-props the props alone (over a chosen playfield) // mt-sun window light (four panes) — drifted slowly, ADD blend // mt-tail the cat's tail (flicks now and then) // mt-tc-- domino faces with coloured pips (mt-tk-… classic black) // mt-back, mt-tshadow, mt-glow, mt-slot // mt-hub the station hub (turned maple, brass ring, slot notches) // mt-engine- toy locomotive markers (seat colours + 'm' Mexican) // mt-card / mt-seat / mt-pad / mt-rack / mt-mini paper + wood furniture // mt-mote, mt-steam, mt-spark, mt-badge import { canvas, rr } from '../../ui/casino/CasinoArt.js'; import { W, H, HUB, STATUS, TALK, SEAT_CARDS, RACK, SCORE_PAD, BONEYARD, RACK_TILE, TILE, } from './MexicanTrainLayout.js'; export const DISPLAY_FONT = 'Righteous, Georgia, serif'; export const SERIF = 'Georgia, "Times New Roman", serif'; export const HAND_FONT = 'YummyCupcakes, "Comic Sans MS", cursive'; export const PRINT_FONT = '"Julius Sans One", Georgia, serif'; export const RES = 2; // texture px per screen px (rack size) export const TEX = { w: RACK_TILE.u * 2 * RES, h: RACK_TILE.u * RES }; // horizontal face texture export const TABLE_SCALE = TILE.u / RACK_TILE.u / RES; // texture → table tile at zoom 1 export const RACK_SCALE = 1 / RES; // Seat colours (seat 0 = you), and the Mexican Train's. export const SEAT = [ { name: 'cherry', base: '#c23b2e', light: '#ec6a52', dark: '#6e1810', hex: 0xc23b2e, ink: '#a1281c' }, { name: 'blue', base: '#2e64ad', light: '#5d93d8', dark: '#132f5c', hex: 0x2e64ad, ink: '#24508c' }, { name: 'green', base: '#3a8f47', light: '#6cc178', dark: '#173f1e', hex: 0x3a8f47, ink: '#2b6e35' }, { name: 'gold', base: '#d39a1e', light: '#f5c95a', dark: '#6e4c06', hex: 0xd39a1e, ink: '#8e6408' }, ]; export const MEX = { name: 'mexican', base: '#7a4bb0', light: '#a985da', dark: '#3a1e5e', hex: 0x7a4bb0, ink: '#5e3590' }; export const colorOf = (key) => (key === 'mexican' ? MEX : SEAT[Number(key)] ?? SEAT[0]); // Pip colours by number, like a real Mexican Train set (index 0 unused). export const PIP_COLORS = [ '#222', '#2f8fd8', '#2e9a45', '#d23c32', '#8a5a2b', '#23408f', '#d9a514', '#8a4fc0', '#138a86', '#c2367f', '#e0742a', '#6f7d1c', '#3a3a3a', ]; export const PIP_HEX = PIP_COLORS.map((c) => parseInt(c.length === 4 ? c.slice(1).split('').map((x) => x + x).join('') : c.slice(1), 16)); function addCanvas(scene, key, c) { if (scene.textures.exists(key)) scene.textures.remove(key); scene.textures.addCanvas(key, c); } function seeded(seed) { let a = seed >>> 0; return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } function shadowed(ctx, fn, { blur = 18, dx = 6, dy = 10, alpha = 0.45 } = {}) { ctx.save(); ctx.shadowColor = `rgba(20,8,0,${alpha})`; ctx.shadowBlur = blur; ctx.shadowOffsetX = dx; ctx.shadowOffsetY = dy; fn(); ctx.restore(); } // ── the table ──────────────────────────────────────────────────────────────── const PLANK_H = 136; const PLANK_TONES = ['#c88f4e', '#c08646', '#cf985a', '#bd8445', '#c99352', '#c48b4b', '#d09b5d', '#c1884a', '#c68e4f']; function paintPlanks(ctx, rnd) { for (let i = 0, y = -24; y < H; i++, y += PLANK_H) { const tone = PLANK_TONES[i % PLANK_TONES.length]; const g = ctx.createLinearGradient(0, y, 0, y + PLANK_H); g.addColorStop(0, tone); g.addColorStop(0.5, shade(tone, 6)); g.addColorStop(1, shade(tone, -10)); ctx.fillStyle = g; ctx.fillRect(0, y, W, PLANK_H); // grain ctx.save(); ctx.beginPath(); ctx.rect(0, y, W, PLANK_H); ctx.clip(); for (let k = 0; k < 46; k++) { const oy = y + rnd() * PLANK_H, amp = 2 + rnd() * 6, f = 0.002 + rnd() * 0.006, ph = rnd() * 6; ctx.strokeStyle = `rgba(${rnd() < 0.5 ? '90,48,14' : '120,70,28'},${0.06 + rnd() * 0.12})`; ctx.lineWidth = 0.6 + rnd() * 1.8; ctx.beginPath(); for (let x = -10; x <= W + 10; x += 8) { const yy = oy + Math.sin(x * f + ph) * amp + Math.sin(x * f * 3.7 + ph * 2) * amp * 0.25; if (x < 0) ctx.moveTo(x, yy); else ctx.lineTo(x, yy); } ctx.stroke(); } // cathedral arches for (let k = 0; k < 2; k++) { const cx = rnd() * W, cy = y + PLANK_H * (0.35 + rnd() * 0.3); for (let r = 0; r < 7; r++) { ctx.strokeStyle = `rgba(100,54,18,${0.08 + rnd() * 0.06})`; ctx.lineWidth = 1.2; ctx.beginPath(); ctx.ellipse(cx, cy, 120 + r * 34, 16 + r * 7, 0, Math.PI * 1.05, Math.PI * 1.95); ctx.stroke(); } } // a knot or two for (let k = 0; k < (rnd() < 0.6 ? 1 : 2); k++) { const kx = 80 + rnd() * (W - 160), ky = y + 30 + rnd() * (PLANK_H - 60); for (let r = 6; r >= 1; r--) { ctx.fillStyle = `rgba(${70 + r * 8},${38 + r * 4},${12 + r * 2},${0.12 + (6 - r) * 0.06})`; ctx.beginPath(); ctx.ellipse(kx, ky, 4 + r * 5, 2 + r * 2.2, 0, 0, Math.PI * 2); ctx.fill(); } ctx.fillStyle = 'rgba(52,24,6,0.7)'; ctx.beginPath(); ctx.ellipse(kx, ky, 5, 2.5, 0, 0, Math.PI * 2); ctx.fill(); } ctx.restore(); // butt joint const jx = 200 + rnd() * (W - 400); ctx.fillStyle = 'rgba(50,22,4,0.55)'; ctx.fillRect(jx, y + 2, 2, PLANK_H - 4); // seam with a worn highlight ctx.fillStyle = 'rgba(46,20,4,0.75)'; ctx.fillRect(0, y + PLANK_H - 2, W, 3); ctx.fillStyle = 'rgba(255,228,180,0.18)'; ctx.fillRect(0, y + PLANK_H + 1, W, 2); } // pores for (let i = 0; i < 9000; i++) { ctx.fillStyle = `rgba(70,34,8,${0.05 + rnd() * 0.1})`; ctx.fillRect(rnd() * W, rnd() * H, 1 + rnd() * 3, 1); } } function shade(hex, amt) { const n = parseInt(hex.slice(1), 16); const c = (v) => Math.max(0, Math.min(255, v + amt)); return `rgb(${c((n >> 16) & 255)},${c((n >> 8) & 255)},${c(n & 255)})`; } function paintWear(ctx, rnd) { // a lighter worn patch where hands rest, a few scratches, and a coffee ring const wp = ctx.createRadialGradient(960, 1000, 40, 960, 1000, 520); wp.addColorStop(0, 'rgba(255,226,170,0.16)'); wp.addColorStop(1, 'rgba(255,226,170,0)'); ctx.fillStyle = wp; ctx.fillRect(0, 0, W, H); for (let i = 0; i < 70; i++) { const x = rnd() * W, y = rnd() * H, len = 10 + rnd() * 60, a = (rnd() - 0.5) * 0.8; ctx.strokeStyle = `rgba(255,236,200,${0.05 + rnd() * 0.08})`; ctx.lineWidth = 0.8; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + Math.cos(a) * len, y + Math.sin(a) * len); ctx.stroke(); } const ring = (x, y, r, a) => { ctx.strokeStyle = `rgba(92,48,16,${a})`; ctx.lineWidth = 3.5; ctx.beginPath(); ctx.arc(x, y, r, 0.3, Math.PI * 1.75); ctx.stroke(); ctx.lineWidth = 1.2; ctx.beginPath(); ctx.arc(x + 2, y + 1, r - 4, 0.5, Math.PI * 1.4); ctx.stroke(); }; ring(1240, 840, 40, 0.22); ring(430, 230, 34, 0.14); } function paintDoily(ctx) { const c = canvas(420, 420), d = c.getContext('2d'); const cx = 210, cy = 210, R = 176; d.fillStyle = 'rgba(252,248,238,0.92)'; d.beginPath(); for (let i = 0; i <= 360; i++) { const a = (i / 360) * Math.PI * 2; const r = R + Math.cos(a * 24) * 9; const x = cx + Math.cos(a) * r, y = cy + Math.sin(a) * r; if (i === 0) d.moveTo(x, y); else d.lineTo(x, y); } d.fill(); // lace holes d.globalCompositeOperation = 'destination-out'; const holeRing = (rad, count, size) => { for (let k = 0; k < count; k++) { const a = (k / count) * Math.PI * 2; d.beginPath(); d.arc(cx + Math.cos(a) * rad, cy + Math.sin(a) * rad, size, 0, Math.PI * 2); d.fill(); } }; holeRing(R - 12, 24, 5.5); holeRing(R - 34, 36, 4.2); holeRing(R - 56, 30, 6); holeRing(R - 80, 24, 4); holeRing(R - 100, 18, 5); for (let k = 0; k < 12; k++) { const a = (k / 12) * Math.PI * 2; d.beginPath(); d.ellipse(cx + Math.cos(a) * 40, cy + Math.sin(a) * 40, 14, 5, a, 0, Math.PI * 2); d.fill(); } d.globalCompositeOperation = 'source-over'; d.strokeStyle = 'rgba(200,190,170,0.6)'; d.lineWidth = 1; for (const rad of [R - 24, R - 46, R - 68, R - 90, R - 112]) { d.beginPath(); d.arc(cx, cy, rad, 0, Math.PI * 2); d.stroke(); } shadowed(ctx, () => ctx.drawImage(c, HUB.x - 210, HUB.y - 210), { blur: 6, dx: 2, dy: 3, alpha: 0.3 }); } // ── props ──────────────────────────────────────────────────────────────────── export const PROPS = { mug: { x: 150, y: 470, r: 46 }, pretzels: { x: 592, y: 70, r: 56 }, pitcher: { x: 1300, y: 70, r: 50 }, glass: { x: 1392, y: 92, r: 27 }, cat: { x: 1772, y: 486 }, }; function paintMug(ctx) { const { x, y, r } = PROPS.mug; shadowed(ctx, () => { ctx.fillStyle = '#e9e2d2'; ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fill(); }, { blur: 16, dx: 8, dy: 12 }); // handle ctx.strokeStyle = '#d8cfbc'; ctx.lineWidth = 11; ctx.beginPath(); ctx.arc(x + r + 6, y + 14, 17, -1.2, 1.9); ctx.stroke(); ctx.strokeStyle = 'rgba(0,0,0,0.12)'; ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(x + r + 6, y + 14, 22, -0.9, 1.6); ctx.stroke(); // rim + a blue band ctx.strokeStyle = '#3d6fa8'; ctx.lineWidth = 5; ctx.beginPath(); ctx.arc(x, y, r - 4, 0, Math.PI * 2); ctx.stroke(); // coffee const g = ctx.createRadialGradient(x - 8, y - 8, 4, x, y, r - 9); g.addColorStop(0, '#6a3c1c'); g.addColorStop(0.7, '#3e2010'); g.addColorStop(1, '#2a1408'); ctx.fillStyle = g; ctx.beginPath(); ctx.arc(x, y, r - 9, 0, Math.PI * 2); ctx.fill(); ctx.strokeStyle = 'rgba(214,170,120,0.45)'; ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(x, y, r - 11, 0, Math.PI * 2); ctx.stroke(); ctx.fillStyle = 'rgba(255,244,220,0.35)'; ctx.beginPath(); ctx.ellipse(x - 12, y - 14, 12, 5, -0.6, 0, Math.PI * 2); ctx.fill(); } function paintPretzels(ctx, rnd) { const { x, y, r } = PROPS.pretzels; shadowed(ctx, () => { ctx.fillStyle = '#6b8fb3'; ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fill(); }, { blur: 16, dx: 8, dy: 12 }); const g = ctx.createRadialGradient(x - 10, y - 10, 6, x, y, r); g.addColorStop(0, '#f2f4f6'); g.addColorStop(0.85, '#c8d4e0'); g.addColorStop(1, '#6b8fb3'); ctx.fillStyle = g; ctx.beginPath(); ctx.arc(x, y, r - 5, 0, Math.PI * 2); ctx.fill(); for (let i = 0; i < 9; i++) { const a = rnd() * Math.PI * 2, d = rnd() * (r - 26); pretzel(ctx, x + Math.cos(a) * d, y + Math.sin(a) * d, 12 + rnd() * 3, rnd() * 6); } } function pretzel(ctx, x, y, s, rot) { ctx.save(); ctx.translate(x, y); ctx.rotate(rot); ctx.strokeStyle = '#7a3e12'; ctx.lineWidth = 5.5; ctx.lineCap = 'round'; ctx.beginPath(); ctx.moveTo(-s * 0.2, s * 0.8); ctx.bezierCurveTo(-s * 1.4, s * 0.2, -s * 1.1, -s * 1.0, -s * 0.1, -s * 0.4); ctx.bezierCurveTo(s * 1.1, -s * 1.0, s * 1.4, s * 0.2, s * 0.2, s * 0.8); ctx.moveTo(-s * 0.55, -s * 0.05); ctx.lineTo(s * 0.4, s * 0.75); ctx.moveTo(s * 0.55, -s * 0.05); ctx.lineTo(-s * 0.4, s * 0.75); ctx.stroke(); ctx.strokeStyle = 'rgba(255,200,140,0.5)'; ctx.lineWidth = 1.6; ctx.stroke(); ctx.fillStyle = 'rgba(255,255,255,0.85)'; for (let i = 0; i < 4; i++) ctx.fillRect((Math.sin(i * 7 + rot) * s * 0.8), (Math.cos(i * 5 + rot) * s * 0.5), 2, 1.5); ctx.restore(); } function paintPitcher(ctx, rnd) { const { x, y, r } = PROPS.pitcher; shadowed(ctx, () => { ctx.fillStyle = 'rgba(240,232,160,0.75)'; ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fill(); }, { blur: 14, dx: 8, dy: 12, alpha: 0.32 }); // handle + spout ctx.strokeStyle = 'rgba(230,240,240,0.8)'; ctx.lineWidth = 9; ctx.beginPath(); ctx.arc(x - r - 4, y + 4, 15, 1.4, 4.9); ctx.stroke(); ctx.fillStyle = 'rgba(235,240,230,0.7)'; ctx.beginPath(); ctx.moveTo(x + r - 6, y - 12); ctx.lineTo(x + r + 16, y); ctx.lineTo(x + r - 6, y + 12); ctx.fill(); const g = ctx.createRadialGradient(x - 14, y - 14, 4, x, y, r); g.addColorStop(0, 'rgba(255,252,210,0.95)'); g.addColorStop(1, 'rgba(240,214,90,0.9)'); ctx.fillStyle = g; ctx.beginPath(); ctx.arc(x, y, r - 5, 0, Math.PI * 2); ctx.fill(); lemon(ctx, x + 10, y - 8, 15); lemon(ctx, x - 16, y + 14, 13); for (let i = 0; i < 4; i++) { const a = rnd() * 6, d = 10 + rnd() * 20; ctx.save(); ctx.translate(x + Math.cos(a) * d, y + Math.sin(a) * d); ctx.rotate(rnd() * 2); ctx.fillStyle = 'rgba(255,255,255,0.55)'; rr(ctx, -8, -8, 16, 16, 4); ctx.fill(); ctx.strokeStyle = 'rgba(255,255,255,0.8)'; ctx.lineWidth = 1; ctx.stroke(); ctx.restore(); } ctx.strokeStyle = 'rgba(255,255,255,0.85)'; ctx.lineWidth = 3; ctx.beginPath(); ctx.arc(x, y, r - 3, 0, Math.PI * 2); ctx.stroke(); ctx.strokeStyle = 'rgba(255,255,255,0.6)'; ctx.lineWidth = 4; ctx.beginPath(); ctx.arc(x, y, r - 12, -2.6, -1.6); ctx.stroke(); // the glass beside it, with a wet ring const gl = PROPS.glass; ctx.strokeStyle = 'rgba(80,50,20,0.18)'; ctx.lineWidth = 3; ctx.beginPath(); ctx.arc(gl.x + 6, gl.y + 7, gl.r + 2, 0, Math.PI * 2); ctx.stroke(); const g2 = ctx.createRadialGradient(gl.x - 6, gl.y - 6, 2, gl.x, gl.y, gl.r); g2.addColorStop(0, 'rgba(255,250,200,0.95)'); g2.addColorStop(1, 'rgba(236,210,90,0.85)'); ctx.fillStyle = g2; ctx.beginPath(); ctx.arc(gl.x, gl.y, gl.r, 0, Math.PI * 2); ctx.fill(); ctx.strokeStyle = 'rgba(255,255,255,0.9)'; ctx.lineWidth = 2.5; ctx.stroke(); lemon(ctx, gl.x + 4, gl.y - 2, 9); for (let i = 0; i < 10; i++) { const a = rnd() * 6.28; ctx.fillStyle = 'rgba(255,255,255,0.7)'; ctx.beginPath(); ctx.arc(gl.x + Math.cos(a) * (gl.r + 1), gl.y + Math.sin(a) * (gl.r + 1), 1.4, 0, 6.28); ctx.fill(); } } function lemon(ctx, x, y, r) { ctx.fillStyle = '#f3d23a'; ctx.beginPath(); ctx.arc(x, y, r, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#fff6b8'; ctx.beginPath(); ctx.arc(x, y, r - 2.5, 0, Math.PI * 2); ctx.fill(); ctx.strokeStyle = '#f0c428'; ctx.lineWidth = 1.4; for (let k = 0; k < 8; k++) { const a = (k / 8) * Math.PI * 2; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + Math.cos(a) * (r - 3), y + Math.sin(a) * (r - 3)); ctx.stroke(); } } function paintCat(ctx, rnd) { const { x, y } = PROPS.cat; shadowed(ctx, () => { ctx.fillStyle = '#d98a3c'; ctx.beginPath(); ctx.ellipse(x, y, 92, 64, -0.18, 0, Math.PI * 2); ctx.fill(); }, { blur: 20, dx: 8, dy: 12, alpha: 0.4 }); const g = ctx.createRadialGradient(x - 20, y - 20, 10, x, y, 96); g.addColorStop(0, '#f2a858'); g.addColorStop(0.75, '#d6853a'); g.addColorStop(1, '#a85e22'); ctx.fillStyle = g; ctx.beginPath(); ctx.ellipse(x, y, 92, 64, -0.18, 0, Math.PI * 2); ctx.fill(); // tabby stripes ctx.strokeStyle = 'rgba(140,70,20,0.55)'; ctx.lineWidth = 7; ctx.lineCap = 'round'; for (let i = -3; i <= 3; i++) { ctx.beginPath(); ctx.arc(x + i * 22 + 10, y - 70, 64, Math.PI * 0.35, Math.PI * 0.62); ctx.stroke(); } // head tucked in, front left const hx = x - 64, hy = y + 22; ctx.fillStyle = '#e8984a'; ctx.beginPath(); ctx.ellipse(hx, hy, 40, 34, 0.4, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#d6853a'; ctx.beginPath(); ctx.moveTo(hx - 30, hy - 14); ctx.lineTo(hx - 42, hy - 46); ctx.lineTo(hx - 10, hy - 30); ctx.fill(); ctx.beginPath(); ctx.moveTo(hx + 4, hy - 30); ctx.lineTo(hx + 18, hy - 58); ctx.lineTo(hx + 30, hy - 20); ctx.fill(); ctx.fillStyle = '#f4b8a8'; ctx.beginPath(); ctx.moveTo(hx - 28, hy - 18); ctx.lineTo(hx - 37, hy - 40); ctx.lineTo(hx - 15, hy - 29); ctx.fill(); ctx.beginPath(); ctx.moveTo(hx + 7, hy - 30); ctx.lineTo(hx + 17, hy - 50); ctx.lineTo(hx + 25, hy - 22); ctx.fill(); ctx.strokeStyle = 'rgba(140,70,20,0.6)'; ctx.lineWidth = 4; for (let i = 0; i < 3; i++) { ctx.beginPath(); ctx.moveTo(hx - 12 + i * 10, hy - 28); ctx.lineTo(hx - 10 + i * 10, hy - 14); ctx.stroke(); } // closed eyes (sleeping) ctx.strokeStyle = '#4a2a10'; ctx.lineWidth = 2.5; ctx.beginPath(); ctx.arc(hx - 16, hy - 2, 7, 0.2, Math.PI - 0.2); ctx.stroke(); ctx.beginPath(); ctx.arc(hx + 10, hy + 6, 7, 0.2, Math.PI - 0.2); ctx.stroke(); ctx.fillStyle = '#e07a82'; ctx.beginPath(); ctx.arc(hx - 6, hy + 14, 4, 0, Math.PI * 2); ctx.fill(); // white paw peeking out ctx.fillStyle = '#fbefe0'; ctx.beginPath(); ctx.ellipse(hx + 30, hy + 30, 16, 10, 0.3, 0, Math.PI * 2); ctx.fill(); void rnd; } function bakeTail(scene) { const c = canvas(150, 50), d = c.getContext('2d'); d.lineCap = 'round'; d.strokeStyle = '#c97a34'; d.lineWidth = 22; d.beginPath(); d.moveTo(12, 25); d.quadraticCurveTo(70, 4, 136, 26); d.stroke(); d.strokeStyle = 'rgba(140,70,20,0.6)'; d.lineWidth = 6; for (let i = 0; i < 5; i++) { d.beginPath(); d.moveTo(28 + i * 22, 6); d.lineTo(30 + i * 22, 30); d.stroke(); } addCanvas(scene, 'mt-tail', c); } function paintBox(ctx, rnd) { const { x, y } = BONEYARD.box; const w = 210, h = 74; shadowed(ctx, () => { ctx.fillStyle = '#7a4a22'; rr(ctx, x - w / 2, y - h / 2, w, h, 8); ctx.fill(); }, { blur: 16, dx: 6, dy: 10 }); ctx.fillStyle = '#8c5528'; rr(ctx, x - w / 2, y - h / 2, w, h, 8); ctx.fill(); ctx.fillStyle = '#3a200c'; rr(ctx, x - w / 2 + 10, y - h / 2 + 10, w - 20, h - 20, 4); ctx.fill(); ctx.fillStyle = '#5a3216'; for (let i = 1; i < 4; i++) ctx.fillRect(x - w / 2 + 10 + i * (w - 20) / 4, y - h / 2 + 10, 3, h - 20); for (let i = 0; i < 14; i++) { ctx.strokeStyle = `rgba(60,30,8,${0.2 + rnd() * 0.2})`; ctx.lineWidth = 1; const yy = y - h / 2 + 2 + rnd() * 8; ctx.beginPath(); ctx.moveTo(x - w / 2 + 4, yy); ctx.lineTo(x + w / 2 - 4, yy + rnd() * 2); ctx.stroke(); } // the lid, slid off at an angle ctx.save(); ctx.translate(x + 30, y - 52); ctx.rotate(-0.12); shadowed(ctx, () => { ctx.fillStyle = '#9a6030'; rr(ctx, -w / 2, -18, w, 30, 6); ctx.fill(); }, { blur: 10, dx: 4, dy: 7 }); ctx.fillStyle = '#a5683a'; rr(ctx, -w / 2, -18, w, 30, 6); ctx.fill(); ctx.fillStyle = 'rgba(255,230,190,0.7)'; ctx.font = `bold 15px ${SERIF}`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText('DOUBLE TWELVE', 0, -3); ctx.restore(); } // ── room ───────────────────────────────────────────────────────────────────── function paintVignette(ctx) { const v = ctx.createRadialGradient(W * 0.42, H * 0.38, 200, W / 2, H / 2, 1150); v.addColorStop(0, 'rgba(255,214,150,0.10)'); v.addColorStop(0.55, 'rgba(0,0,0,0)'); v.addColorStop(1, 'rgba(30,10,0,0.55)'); ctx.fillStyle = v; ctx.fillRect(0, 0, W, H); } function paintProps(ctx, rnd) { paintBox(ctx, rnd); paintMug(ctx); paintPretzels(ctx, rnd); paintPitcher(ctx, rnd); paintCat(ctx, rnd); } function bakeRoom(scene) { const rnd = seeded(20261125); const c = canvas(W, H), ctx = c.getContext('2d'); paintPlanks(ctx, rnd); paintWear(ctx, rnd); paintDoily(ctx); paintProps(ctx, rnd); paintVignette(ctx); addCanvas(scene, 'mt-room', c); const v = canvas(W, H); paintVignette(v.getContext('2d')); addCanvas(scene, 'mt-vignette', v); const p = canvas(W, H); paintProps(p.getContext('2d'), seeded(20261125)); addCanvas(scene, 'mt-props', p); } function bakeSun(scene) { // four window panes thrown across the table, soft edged const c = canvas(900, 700), d = c.getContext('2d'); d.filter = 'blur(18px)'; const pane = (x, y) => { d.beginPath(); d.moveTo(x, y); d.lineTo(x + 260, y + 40); d.lineTo(x + 330, y + 300); d.lineTo(x + 70, y + 260); d.closePath(); d.fill(); }; d.fillStyle = 'rgba(255,214,140,0.55)'; pane(80, 40); pane(380, 86); pane(150, 340); pane(450, 386); d.filter = 'none'; addCanvas(scene, 'mt-sun', c); } // ── dominoes ───────────────────────────────────────────────────────────────── const G = 0.6; const PIPS = { 0: [], 1: [[0, 0]], 2: [[-G, -G], [G, G]], 3: [[-G, -G], [0, 0], [G, G]], 4: [[-G, -G], [G, -G], [-G, G], [G, G]], 5: [[-G, -G], [G, -G], [0, 0], [-G, G], [G, G]], 6: [[-G, -G], [-G, 0], [-G, G], [G, -G], [G, 0], [G, G]], 7: [[-G, -G], [-G, 0], [-G, G], [G, -G], [G, 0], [G, G], [0, 0]], 8: [[-G, -G], [-G, 0], [-G, G], [G, -G], [G, 0], [G, G], [0, -G], [0, G]], 9: [[-G, -G], [-G, 0], [-G, G], [G, -G], [G, 0], [G, G], [0, -G], [0, G], [0, 0]], }; const R4 = [-0.68, -0.23, 0.23, 0.68]; PIPS[10] = [...R4.map((y) => [-G, y]), ...R4.map((y) => [G, y]), [0, -0.35], [0, 0.35]]; PIPS[11] = [...R4.map((y) => [-G, y]), ...R4.map((y) => [G, y]), [0, -0.5], [0, 0], [0, 0.5]]; PIPS[12] = [...R4.map((y) => [-G, y]), ...R4.map((y) => [G, y]), ...R4.map((y) => [0, y])]; function tileBody(d, w, h, back = false) { const r = h * 0.14; // thickness (the side you see below / right) d.fillStyle = '#c4b28a'; rr(d, 1.5, 3, w - 3, h - 4, r); d.fill(); const g = d.createLinearGradient(0, 0, w * 0.3, h); g.addColorStop(0, back ? '#f7eedb' : '#fffaf0'); g.addColorStop(1, back ? '#e4d5b4' : '#ede2c6'); d.fillStyle = g; rr(d, 1, 1, w - 3, h - 5, r); d.fill(); d.strokeStyle = 'rgba(255,255,255,0.8)'; d.lineWidth = 1.5; rr(d, 2.5, 2.5, w - 6, h - 8, r * 0.8); d.stroke(); d.strokeStyle = 'rgba(120,96,56,0.55)'; d.lineWidth = 1; rr(d, 1, 1, w - 3, h - 5, r); d.stroke(); } function drawPips(d, cx, cy, s, v, colored) { const pts = PIPS[v] ?? []; const pr = v >= 10 ? s * 0.105 : s * 0.13; const spread = s * 0.33; for (const [px, py] of pts) { const x = cx + px * spread, y = cy + py * spread; d.fillStyle = 'rgba(80,60,30,0.35)'; d.beginPath(); d.arc(x + 0.6, y + 0.9, pr + 0.9, 0, Math.PI * 2); d.fill(); d.fillStyle = colored ? PIP_COLORS[v] : '#1d1a16'; d.beginPath(); d.arc(x, y, pr, 0, Math.PI * 2); d.fill(); d.fillStyle = 'rgba(255,255,255,0.35)'; d.beginPath(); d.arc(x - pr * 0.3, y - pr * 0.35, pr * 0.35, 0, Math.PI * 2); d.fill(); } } export const tileKey = (a, b, colored) => `mt-t${colored ? 'c' : 'k'}-${Math.min(a, b)}-${Math.max(a, b)}`; /** Bake every face of a set (idempotent per colour scheme). */ export function bakeTiles(scene, set, colored) { const w = TEX.w, h = TEX.h; for (let a = 0; a <= set; a++) { for (let b = a; b <= set; b++) { const key = tileKey(a, b, colored); if (scene.textures.exists(key)) continue; const c = canvas(w, h), d = c.getContext('2d'); tileBody(d, w, h); // divider groove + brass spinner d.strokeStyle = 'rgba(110,86,50,0.6)'; d.lineWidth = 2; d.beginPath(); d.moveTo(w / 2, h * 0.14); d.lineTo(w / 2, h * 0.8); d.stroke(); d.strokeStyle = 'rgba(255,255,255,0.7)'; d.lineWidth = 1; d.beginPath(); d.moveTo(w / 2 + 1.5, h * 0.14); d.lineTo(w / 2 + 1.5, h * 0.8); d.stroke(); const sg = d.createRadialGradient(w / 2 - 1, h * 0.47 - 1, 0.5, w / 2, h * 0.47, h * 0.07); sg.addColorStop(0, '#fff2b8'); sg.addColorStop(0.5, '#c89a3a'); sg.addColorStop(1, '#7a5418'); d.fillStyle = sg; d.beginPath(); d.arc(w / 2, h * 0.47, h * 0.065, 0, Math.PI * 2); d.fill(); const s = h - 6; drawPips(d, w * 0.25, h * 0.47, s, a, colored); drawPips(d, w * 0.75, h * 0.47, s, b, colored); addCanvas(scene, key, c); } } } function bakeTileBits(scene) { const w = TEX.w, h = TEX.h; const c = canvas(w, h), d = c.getContext('2d'); tileBody(d, w, h, true); // a little embossed locomotive d.fillStyle = 'rgba(150,120,70,0.35)'; d.save(); d.translate(w / 2, h * 0.47); rr(d, -h * 0.5, -h * 0.16, h * 0.62, h * 0.3, 3); d.fill(); rr(d, h * 0.12, -h * 0.26, h * 0.3, h * 0.4, 3); d.fill(); d.fillRect(-h * 0.42, -h * 0.3, h * 0.1, h * 0.16); d.beginPath(); d.arc(-h * 0.34, h * 0.2, h * 0.07, 0, 6.28); d.arc(-h * 0.08, h * 0.2, h * 0.07, 0, 6.28); d.arc(h * 0.24, h * 0.2, h * 0.07, 0, 6.28); d.fill(); d.restore(); addCanvas(scene, 'mt-back', c); // soft shadow (drawn under every tile) const pad = 14; const s = canvas(w + pad * 2, h + pad * 2), sd = s.getContext('2d'); sd.filter = 'blur(5px)'; sd.fillStyle = 'rgba(40,18,0,0.55)'; rr(sd, pad, pad, w - 2, h - 3, h * 0.14); sd.fill(); addCanvas(scene, 'mt-tshadow', s); // glow outline const gl = canvas(w + 40, h + 40), gd = gl.getContext('2d'); gd.filter = 'blur(6px)'; gd.strokeStyle = '#ffffff'; gd.lineWidth = 10; rr(gd, 20, 20, w, h - 4, h * 0.16); gd.stroke(); gd.filter = 'none'; gd.strokeStyle = 'rgba(255,255,255,0.95)'; gd.lineWidth = 4; rr(gd, 20, 20, w, h - 4, h * 0.16); gd.stroke(); addCanvas(scene, 'mt-glow', gl); // drop slot (dashed) const sl = canvas(w + 8, h + 8), sld = sl.getContext('2d'); sld.fillStyle = 'rgba(255,248,226,0.28)'; rr(sld, 4, 4, w, h - 2, h * 0.16); sld.fill(); sld.setLineDash([10, 7]); sld.strokeStyle = 'rgba(255,250,236,0.95)'; sld.lineWidth = 4; rr(sld, 4, 4, w, h - 2, h * 0.16); sld.stroke(); addCanvas(scene, 'mt-slot', sl); } // ── hub + markers ──────────────────────────────────────────────────────────── function bakeHub(scene) { const R = HUB.r, S = (R + 14) * 2 * RES; const c = canvas(S, S), d = c.getContext('2d'); d.scale(RES, RES); const cx = R + 14, cy = R + 14; shadowed(d, () => { d.fillStyle = '#b88a52'; d.beginPath(); d.arc(cx, cy, R, 0, Math.PI * 2); d.fill(); }, { blur: 12, dx: 4, dy: 7, alpha: 0.5 }); const g = d.createRadialGradient(cx - 18, cy - 18, 6, cx, cy, R); g.addColorStop(0, '#f2d6a6'); g.addColorStop(0.7, '#d4a86c'); g.addColorStop(1, '#a87a44'); d.fillStyle = g; d.beginPath(); d.arc(cx, cy, R, 0, Math.PI * 2); d.fill(); // turned rings for (let r = R - 3; r > 10; r -= 5) { d.strokeStyle = `rgba(120,78,34,${0.1 + (r % 10 === 0 ? 0.1 : 0)})`; d.lineWidth = 1; d.beginPath(); d.arc(cx, cy, r, 0, Math.PI * 2); d.stroke(); } d.strokeStyle = '#c9a046'; d.lineWidth = 3.5; d.beginPath(); d.arc(cx, cy, R - 2, 0, Math.PI * 2); d.stroke(); d.strokeStyle = 'rgba(255,240,190,0.7)'; d.lineWidth = 1; d.beginPath(); d.arc(cx, cy, R - 3.5, Math.PI * 1.05, Math.PI * 1.7); d.stroke(); // slot notches round the rim for (let k = 0; k < 8; k++) { const a = (k / 8) * Math.PI * 2 + Math.PI / 8; d.save(); d.translate(cx + Math.cos(a) * (R - 11), cy + Math.sin(a) * (R - 11)); d.rotate(a); d.fillStyle = 'rgba(80,46,14,0.6)'; rr(d, -6, -4, 12, 8, 3); d.fill(); d.restore(); } // centre recess for the engine d.fillStyle = 'rgba(90,52,18,0.55)'; rr(d, cx - 40, cy - 22, 80, 44, 8); d.fill(); d.strokeStyle = 'rgba(255,230,180,0.5)'; d.lineWidth = 1.2; rr(d, cx - 40, cy - 22, 80, 44, 8); d.stroke(); addCanvas(scene, 'mt-hub', c); } function bakeEngine(scene, key, col) { const w = 64, h = 34; const c = canvas(w * RES, h * RES), d = c.getContext('2d'); d.scale(RES, RES); // wheels d.fillStyle = '#1c1a18'; for (const x of [12, 25, 38, 50]) { rr(d, x - 4, 2, 9, 5, 2); d.fill(); rr(d, x - 4, h - 7, 9, 5, 2); d.fill(); } shadowed(d, () => { d.fillStyle = col.base; rr(d, 4, 6, 56, 22, 6); d.fill(); }, { blur: 5, dx: 2, dy: 3, alpha: 0.45 }); const g = d.createLinearGradient(0, 6, 0, 28); g.addColorStop(0, col.light); g.addColorStop(1, col.dark); d.fillStyle = g; rr(d, 4, 6, 56, 22, 6); d.fill(); // cab at the back (left), boiler bands, smokestack at the front (right) d.fillStyle = col.dark; rr(d, 4, 4, 18, 26, 4); d.fill(); d.fillStyle = 'rgba(255,255,255,0.3)'; rr(d, 7, 8, 12, 6, 2); d.fill(); d.strokeStyle = '#e8c46a'; d.lineWidth = 1.6; for (const x of [30, 40, 50]) { d.beginPath(); d.moveTo(x, 7); d.lineTo(x, 27); d.stroke(); } d.fillStyle = '#222'; d.beginPath(); d.arc(48, 17, 4.5, 0, Math.PI * 2); d.fill(); d.fillStyle = '#e8c46a'; d.beginPath(); d.arc(58, 17, 3, 0, Math.PI * 2); d.fill(); d.fillStyle = '#c9a046'; d.beginPath(); d.moveTo(60, 8); d.lineTo(64, 17); d.lineTo(60, 26); d.fill(); addCanvas(scene, key, c); } // ── paper + wood furniture ─────────────────────────────────────────────────── export function bakeCard(scene, key, w, h, { ruled = true, tape = true, tint = '#fbf6ea' } = {}) { const pad = 14; const c = canvas((w + pad * 2) * RES, (h + pad * 2) * RES), d = c.getContext('2d'); d.scale(RES, RES); shadowed(d, () => { d.fillStyle = tint; rr(d, pad, pad, w, h, 6); d.fill(); }, { blur: 12, dx: 4, dy: 7, alpha: 0.4 }); d.fillStyle = tint; rr(d, pad, pad, w, h, 6); d.fill(); if (ruled) { d.strokeStyle = 'rgba(90,130,190,0.28)'; d.lineWidth = 1; for (let y = pad + 34; y < pad + h - 6; y += 22) { d.beginPath(); d.moveTo(pad + 8, y); d.lineTo(pad + w - 8, y); d.stroke(); } d.strokeStyle = 'rgba(210,80,80,0.45)'; d.beginPath(); d.moveTo(pad + 8, pad + 26); d.lineTo(pad + w - 8, pad + 26); d.stroke(); } if (tape) { d.save(); d.translate(pad + w / 2, pad + 2); d.rotate(-0.04); d.fillStyle = 'rgba(240,228,190,0.75)'; d.fillRect(-36, -9, 72, 18); d.restore(); } addCanvas(scene, key, c); } function bakePad(scene) { const { w, h } = SCORE_PAD; const pad = 16; const c = canvas((w + pad * 2) * RES, (h + pad * 2) * RES), d = c.getContext('2d'); d.scale(RES, RES); shadowed(d, () => { d.fillStyle = '#f7ec9e'; rr(d, pad, pad + 8, w, h - 8, 4); d.fill(); }, { blur: 14, dx: 5, dy: 9 }); d.fillStyle = '#f7ec9e'; rr(d, pad, pad + 8, w, h - 8, 4); d.fill(); d.strokeStyle = 'rgba(70,110,170,0.4)'; d.lineWidth = 1; for (let y = pad + 60; y < pad + h - 8; y += 26) { d.beginPath(); d.moveTo(pad + 4, y); d.lineTo(pad + w - 4, y); d.stroke(); } d.strokeStyle = 'rgba(200,60,60,0.5)'; d.beginPath(); d.moveTo(pad + 40, pad + 30); d.lineTo(pad + 40, pad + h - 6); d.stroke(); // spiral for (let x = pad + 14; x < pad + w - 8; x += 18) { d.strokeStyle = '#8a8a90'; d.lineWidth = 3; d.beginPath(); d.ellipse(x, pad + 10, 4, 9, 0, 0, Math.PI * 2); d.stroke(); d.fillStyle = '#3a2a1a'; d.beginPath(); d.arc(x, pad + 18, 2.5, 0, Math.PI * 2); d.fill(); } addCanvas(scene, 'mt-pad', c); // the pencil (its own sprite so it can scribble) const pc = canvas(220 * RES, 22 * RES), p = pc.getContext('2d'); p.scale(RES, RES); p.fillStyle = '#f2b52c'; p.fillRect(30, 4, 160, 14); p.fillStyle = 'rgba(255,255,255,0.35)'; p.fillRect(30, 5, 160, 3); p.fillStyle = '#c8c8cc'; p.fillRect(190, 3, 12, 16); p.fillStyle = '#e8828a'; rr(p, 200, 3, 18, 16, 4); p.fill(); p.fillStyle = '#ecc89a'; p.beginPath(); p.moveTo(30, 4); p.lineTo(6, 11); p.lineTo(30, 18); p.fill(); p.fillStyle = '#333'; p.beginPath(); p.moveTo(12, 9.3); p.lineTo(2, 11); p.lineTo(12, 12.7); p.fill(); addCanvas(scene, 'mt-pencil', pc); } function bakeRack(scene) { const { w, h } = RACK; const pad = 14; const c = canvas((w + pad * 2) * RES, (h + pad * 2) * RES), d = c.getContext('2d'); d.scale(RES, RES); const rnd = seeded(77); shadowed(d, () => { d.fillStyle = '#6a3a18'; rr(d, pad, pad + 20, w, h - 20, 12); d.fill(); }, { blur: 16, dx: 5, dy: 10 }); const g = d.createLinearGradient(0, pad + 20, 0, pad + h); g.addColorStop(0, '#8a4e22'); g.addColorStop(0.5, '#74401a'); g.addColorStop(1, '#4e2a10'); d.fillStyle = g; rr(d, pad, pad + 20, w, h - 20, 12); d.fill(); for (let i = 0; i < 30; i++) { d.strokeStyle = `rgba(40,18,4,${0.12 + rnd() * 0.18})`; d.lineWidth = 1 + rnd(); const y = pad + 24 + rnd() * (h - 28); d.beginPath(); d.moveTo(pad + 6, y); d.bezierCurveTo(pad + w * 0.3, y + 3, pad + w * 0.6, y - 3, pad + w - 6, y + rnd() * 2); d.stroke(); } // the ledge the tiles lean on d.fillStyle = '#9a5c2a'; rr(d, pad + 8, pad + h - 26, w - 16, 16, 6); d.fill(); d.fillStyle = 'rgba(255,220,170,0.35)'; d.fillRect(pad + 14, pad + h - 25, w - 28, 2); d.fillStyle = 'rgba(255,220,170,0.25)'; rr(d, pad + 4, pad + 22, w - 8, 3, 2); d.fill(); addCanvas(scene, 'mt-rack', c); // the tiny rack on opponents' seat cards const mc = canvas(240 * RES, 30 * RES), md = mc.getContext('2d'); md.scale(RES, RES); md.fillStyle = '#6e3c1a'; rr(md, 0, 8, 240, 20, 5); md.fill(); md.fillStyle = '#9a5c2a'; rr(md, 3, 20, 234, 7, 3); md.fill(); addCanvas(scene, 'mt-mini', mc); } function bakeBits(scene) { const m = canvas(16, 16), md = m.getContext('2d'); const mg = md.createRadialGradient(8, 8, 0, 8, 8, 8); mg.addColorStop(0, 'rgba(255,240,200,1)'); mg.addColorStop(1, 'rgba(255,240,200,0)'); md.fillStyle = mg; md.fillRect(0, 0, 16, 16); addCanvas(scene, 'mt-mote', m); const st = canvas(64, 64), sd = st.getContext('2d'); const sg = sd.createRadialGradient(32, 32, 0, 32, 32, 32); sg.addColorStop(0, 'rgba(255,255,255,0.5)'); sg.addColorStop(1, 'rgba(255,255,255,0)'); sd.fillStyle = sg; sd.fillRect(0, 0, 64, 64); addCanvas(scene, 'mt-steam', st); const sp = canvas(24, 24), spd = sp.getContext('2d'); const spg = spd.createRadialGradient(12, 12, 0, 12, 12, 12); spg.addColorStop(0, 'rgba(255,255,255,1)'); spg.addColorStop(0.4, 'rgba(255,240,200,0.8)'); spg.addColorStop(1, 'rgba(255,220,150,0)'); spd.fillStyle = spg; spd.fillRect(0, 0, 24, 24); addCanvas(scene, 'mt-spark', sp); // end badge: a little wooden token const b = canvas(60, 60), bd = b.getContext('2d'); shadowed(bd, () => { bd.fillStyle = '#fbf4e2'; bd.beginPath(); bd.arc(30, 30, 22, 0, Math.PI * 2); bd.fill(); }, { blur: 5, dx: 2, dy: 3, alpha: 0.5 }); bd.fillStyle = '#fbf4e2'; bd.beginPath(); bd.arc(30, 30, 22, 0, Math.PI * 2); bd.fill(); addCanvas(scene, 'mt-badge', b); } let baked = false; export async function prepareMexicanTrainArt(scene, { set = 12, colored = true } = {}) { try { if (document.fonts?.load) { await Promise.race([ Promise.all([document.fonts.load('20px Righteous'), document.fonts.load('14px "Julius Sans One"'), document.fonts.load('30px YummyCupcakes')]), new Promise((res) => setTimeout(res, 1200)), ]); } } catch (_) { /* fall back to Georgia */ } if (!baked || !scene.textures.exists('mt-room')) { bakeRoom(scene); bakeSun(scene); bakeTail(scene); bakeTileBits(scene); bakeHub(scene); SEAT.forEach((col, i) => bakeEngine(scene, `mt-engine-${i}`, col)); bakeEngine(scene, 'mt-engine-m', MEX); bakeCard(scene, 'mt-card-status', STATUS.w, STATUS.h); bakeCard(scene, 'mt-card-talk', TALK.w, TALK.h); for (const [k, r] of Object.entries(SEAT_CARDS)) bakeCard(scene, `mt-seat-${k}`, r.w, r.h, { ruled: false, tape: k !== 'human', tint: '#fcf7ec' }); bakeCard(scene, 'mt-card-buttons', 404, 152, { ruled: false, tape: false, tint: '#f3e6cc' }); bakePad(scene); bakeRack(scene); bakeBits(scene); baked = true; } bakeTiles(scene, set, colored); } void H;