254 lines
8.3 KiB
JavaScript
254 lines
8.3 KiB
JavaScript
// Texas Hold 'Em table art — a casino poker-room oval baked once into 'he-table':
|
|
// floor shadow, padded rail with a visible front face, wooden racetrack, lit
|
|
// poker-green felt with a printed betting line, board outlines and lettering,
|
|
// and the dealer's chip rack + nameplate at the far side.
|
|
|
|
import { prepareCasinoArt, canvas, rr, poly, mix, lerp, noisePattern } from '../../ui/casino/CasinoArt.js';
|
|
import { CHIP_DEFS } from '../../ui/CasinoChips.js';
|
|
import {
|
|
P, VIEW, rim, rimPoints, communityPose, dealerSpot, DEALER_PLATE,
|
|
FELT_K, WOOD_K, RAIL_K, RAIL_FACE_PX, RING_K, CARD_W, CARD_H,
|
|
} from './HoldemTable.js';
|
|
|
|
const W = 1920, H = 1080;
|
|
const FELT = '#0f5a33';
|
|
export const TEXT_K = 0.345; // felt lettering sits on this rim fraction (bottom arc)
|
|
const LEATHER_DARK = '#0f0806', LEATHER_MID = '#2c1a12', LEATHER_HI = '#5e3e2b';
|
|
|
|
function bandPath(ctx, k0, k1) {
|
|
const outer = rimPoints(k1, 200), inner = rimPoints(k0, 200);
|
|
ctx.beginPath();
|
|
outer.forEach((p, i) => (i ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y)));
|
|
ctx.closePath();
|
|
inner.forEach((p, i) => (i ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y)));
|
|
ctx.closePath();
|
|
}
|
|
|
|
function ring(ctx, k, width, color) {
|
|
poly(ctx, rimPoints(k, 200));
|
|
ctx.lineWidth = width;
|
|
ctx.strokeStyle = color;
|
|
ctx.stroke();
|
|
}
|
|
|
|
// Text along the rim curve at scale k, centred on the bottom (φ = 0).
|
|
function rimText(ctx, text, k, size, color, { bold = false, alpha = 1, spacing = 1 } = {}) {
|
|
ctx.font = `${bold ? 'bold ' : ''}${size}px "Julius Sans One", sans-serif`;
|
|
ctx.textAlign = 'center';
|
|
ctx.textBaseline = 'middle';
|
|
const pxPerDeg = Math.hypot(rim(0.5, k).x - rim(-0.5, k).x, rim(0.5, k).y - rim(-0.5, k).y);
|
|
const widths = [...text].map(ch => ctx.measureText(ch).width * spacing);
|
|
const totalDeg = widths.reduce((a, b) => a + b, 0) / pxPerDeg;
|
|
let deg = -totalDeg / 2;
|
|
const s0 = rim(0, k).s;
|
|
ctx.save();
|
|
ctx.globalAlpha = alpha;
|
|
ctx.fillStyle = color;
|
|
ctx.shadowColor = 'rgba(0,0,0,0.35)';
|
|
ctx.shadowBlur = 2;
|
|
ctx.shadowOffsetY = 1;
|
|
[...text].forEach((ch, i) => {
|
|
const mid = deg + widths[i] / 2 / pxPerDeg;
|
|
deg += widths[i] / pxPerDeg;
|
|
if (ch === ' ') return;
|
|
const p = rim(mid, k), a = rim(mid - 0.4, k), b = rim(mid + 0.4, k);
|
|
ctx.save();
|
|
ctx.translate(p.x, p.y);
|
|
ctx.rotate(Math.atan2(b.y - a.y, b.x - a.x));
|
|
const sc = p.s / s0;
|
|
ctx.scale(sc, sc * VIEW.squash);
|
|
ctx.fillText(ch, 0, 0);
|
|
ctx.restore();
|
|
});
|
|
ctx.restore();
|
|
}
|
|
|
|
function drawShadow(ctx) {
|
|
const OFF = 6000;
|
|
const pts = rimPoints(RAIL_K, 160).map(p => ({ x: p.x - OFF, y: p.y + RAIL_FACE_PX * p.s }));
|
|
ctx.save();
|
|
ctx.shadowColor = 'rgba(0,0,0,0.7)';
|
|
ctx.shadowBlur = 60;
|
|
ctx.shadowOffsetX = OFF;
|
|
ctx.shadowOffsetY = 26;
|
|
poly(ctx, pts);
|
|
ctx.fillStyle = '#000';
|
|
ctx.fill();
|
|
ctx.restore();
|
|
}
|
|
|
|
function drawRailFace(ctx) {
|
|
const top = rimPoints(RAIL_K, 200);
|
|
const shifted = top.map(p => ({ x: p.x, y: p.y + RAIL_FACE_PX * p.s }));
|
|
// union of the outline and its shifted copy = the visible side of the rail
|
|
ctx.save();
|
|
poly(ctx, shifted);
|
|
ctx.fillStyle = LEATHER_DARK;
|
|
ctx.fill();
|
|
for (let i = 0; i <= 12; i++) {
|
|
const f = i / 12;
|
|
poly(ctx, top.map(p => ({ x: p.x, y: p.y + RAIL_FACE_PX * p.s * f })));
|
|
ctx.lineWidth = 4;
|
|
ctx.strokeStyle = mix(LEATHER_MID, LEATHER_DARK, Math.min(1, f * 1.25));
|
|
ctx.stroke();
|
|
}
|
|
poly(ctx, shifted);
|
|
ctx.lineWidth = 2;
|
|
ctx.strokeStyle = 'rgba(0,0,0,0.8)';
|
|
ctx.stroke();
|
|
ctx.restore();
|
|
}
|
|
|
|
function railColor(f) {
|
|
const ridge = Math.max(0, Math.cos((f - 0.42) * Math.PI * 1.05));
|
|
return ridge > 0.72 ? mix(LEATHER_MID, LEATHER_HI, (ridge - 0.72) / 0.28) : mix(LEATHER_DARK, LEATHER_MID, Math.min(1, ridge * 1.4));
|
|
}
|
|
|
|
function drawRail(ctx) {
|
|
ctx.save();
|
|
bandPath(ctx, WOOD_K, RAIL_K);
|
|
ctx.fillStyle = LEATHER_MID;
|
|
ctx.fill('evenodd');
|
|
ctx.clip('evenodd');
|
|
for (let i = 0; i <= 26; i++) ring(ctx, lerp(WOOD_K, RAIL_K, i / 26), 6, railColor(i / 26));
|
|
ctx.fillStyle = noisePattern(ctx, 128, 26);
|
|
ctx.fillRect(0, 0, W, H);
|
|
ring(ctx, lerp(WOOD_K, RAIL_K, 0.4), 3, 'rgba(255,230,200,0.13)');
|
|
ctx.setLineDash([7, 5]);
|
|
ring(ctx, lerp(WOOD_K, RAIL_K, 0.1), 1.5, 'rgba(214,174,120,0.42)');
|
|
ring(ctx, lerp(WOOD_K, RAIL_K, 0.9), 1.5, 'rgba(214,174,120,0.42)');
|
|
ctx.setLineDash([]);
|
|
ctx.restore();
|
|
}
|
|
|
|
function drawWood(ctx) {
|
|
ctx.save();
|
|
bandPath(ctx, FELT_K, WOOD_K);
|
|
ctx.fillStyle = '#7a4520';
|
|
ctx.fill('evenodd');
|
|
ctx.clip('evenodd');
|
|
for (let i = 0; i <= 10; i++) {
|
|
const f = i / 10;
|
|
ring(ctx, lerp(FELT_K, WOOD_K, f), 4, mix('#5a3216', '#a8692f', Math.sin(f * Math.PI)));
|
|
}
|
|
ctx.fillStyle = noisePattern(ctx, 128, 16);
|
|
ctx.fillRect(0, 0, W, H);
|
|
ctx.restore();
|
|
ring(ctx, WOOD_K, 1.5, 'rgba(0,0,0,0.5)');
|
|
ring(ctx, FELT_K, 1.5, 'rgba(0,0,0,0.6)');
|
|
}
|
|
|
|
function drawFelt(ctx) {
|
|
ctx.save();
|
|
poly(ctx, rimPoints(FELT_K, 200));
|
|
ctx.clip();
|
|
ctx.fillStyle = FELT;
|
|
ctx.fillRect(0, 0, W, H);
|
|
ctx.fillStyle = noisePattern(ctx, 256, 22);
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
// printed betting line
|
|
ring(ctx, RING_K, 3, 'rgba(217,180,90,0.7)');
|
|
ring(ctx, RING_K - 0.017, 1, 'rgba(217,180,90,0.35)');
|
|
|
|
// board outlines
|
|
for (let i = 0; i < 5; i++) {
|
|
const c = communityPose(i);
|
|
ctx.save();
|
|
ctx.translate(c.x, c.y);
|
|
ctx.scale(c.s, c.s * VIEW.squash);
|
|
rr(ctx, -CARD_W / 2 - 5, -CARD_H / 2 - 5, CARD_W + 10, CARD_H + 10, 10);
|
|
ctx.lineWidth = 2 / c.s;
|
|
ctx.strokeStyle = 'rgba(242,234,216,0.28)';
|
|
ctx.stroke();
|
|
ctx.restore();
|
|
}
|
|
|
|
rimText(ctx, "NO LIMIT TEXAS HOLD 'EM", TEXT_K, 28, '#e8c15a', { bold: true, alpha: 0.92, spacing: 1.06 });
|
|
|
|
const c = P.project(0, 0.5);
|
|
const lamp = ctx.createRadialGradient(c.x, c.y, 40, c.x, c.y, 900);
|
|
lamp.addColorStop(0, 'rgba(255,248,210,0.20)');
|
|
lamp.addColorStop(0.45, 'rgba(255,248,210,0.07)');
|
|
lamp.addColorStop(1, 'rgba(255,248,210,0)');
|
|
ctx.fillStyle = lamp;
|
|
ctx.fillRect(0, 0, W, H);
|
|
const vig = ctx.createRadialGradient(c.x, c.y, 360, c.x, c.y, 1000);
|
|
vig.addColorStop(0, 'rgba(0,0,0,0)');
|
|
vig.addColorStop(1, 'rgba(0,0,0,0.5)');
|
|
ctx.fillStyle = vig;
|
|
ctx.fillRect(0, 0, W, H);
|
|
for (let i = 0; i < 10; i++) ring(ctx, FELT_K - i * 0.005, 4, `rgba(0,0,0,${0.32 * (1 - i / 10)})`);
|
|
ctx.restore();
|
|
}
|
|
|
|
// Dealer side: a chip rack set into the rail and a brass nameplate.
|
|
function drawDealer(ctx) {
|
|
const top = rim(180, (WOOD_K + RAIL_K) / 2);
|
|
const w = 300, h = 30, x0 = top.x - w / 2, y0 = top.y - h / 2;
|
|
rr(ctx, x0 - 6, y0 - 5, w + 12, h + 10, 8);
|
|
ctx.fillStyle = '#17110c';
|
|
ctx.fill();
|
|
ctx.lineWidth = 2;
|
|
ctx.strokeStyle = 'rgba(214,174,120,0.55)';
|
|
ctx.stroke();
|
|
const cols = [1, 5, 5, 25, 25, 50, 100, 100, 50, 25, 25, 5, 5, 1];
|
|
const cw = w / cols.length;
|
|
cols.forEach((d, i) => {
|
|
const def = CHIP_DEFS[d];
|
|
for (let k = 0; k < 6; k++) {
|
|
ctx.fillStyle = k % 2 ? def.base : mix(def.base, '#000000', 0.18);
|
|
ctx.fillRect(x0 + i * cw + 1, y0 + k * (h / 6), cw - 2, h / 6 - 0.6);
|
|
}
|
|
const g = ctx.createLinearGradient(x0 + i * cw, 0, x0 + (i + 1) * cw, 0);
|
|
g.addColorStop(0, 'rgba(0,0,0,0.5)');
|
|
g.addColorStop(0.4, 'rgba(255,255,255,0.18)');
|
|
g.addColorStop(1, 'rgba(0,0,0,0.5)');
|
|
ctx.fillStyle = g;
|
|
ctx.fillRect(x0 + i * cw + 1, y0, cw - 2, h);
|
|
});
|
|
|
|
const { x, y } = DEALER_PLATE;
|
|
rr(ctx, x - 92, y - 18, 184, 36, 8);
|
|
const pg = ctx.createLinearGradient(0, y - 18, 0, y + 18);
|
|
pg.addColorStop(0, '#e9c46a');
|
|
pg.addColorStop(1, '#9a7420');
|
|
ctx.fillStyle = pg;
|
|
ctx.fill();
|
|
ctx.lineWidth = 2;
|
|
ctx.strokeStyle = '#5c4210';
|
|
ctx.stroke();
|
|
ctx.font = 'bold 18px "Julius Sans One", sans-serif';
|
|
ctx.textAlign = 'center';
|
|
ctx.textBaseline = 'middle';
|
|
ctx.fillStyle = '#2a1c06';
|
|
ctx.fillText('DEALER', x, y + 1);
|
|
|
|
// a faint dealer's work area on the felt (deck + muck)
|
|
const d = dealerSpot();
|
|
ctx.save();
|
|
ctx.translate(d.x, d.y);
|
|
ctx.scale(d.s, d.s * VIEW.squash);
|
|
rr(ctx, -120, -50, 240, 100, 16);
|
|
ctx.setLineDash([8, 6]);
|
|
ctx.lineWidth = 2 / d.s;
|
|
ctx.strokeStyle = 'rgba(242,234,216,0.18)';
|
|
ctx.stroke();
|
|
ctx.setLineDash([]);
|
|
ctx.restore();
|
|
}
|
|
|
|
export async function prepareHoldemArt(scene) {
|
|
await prepareCasinoArt(scene);
|
|
if (scene.textures.exists('he-table')) return;
|
|
const c = canvas(W, H);
|
|
const ctx = c.getContext('2d');
|
|
drawShadow(ctx);
|
|
drawRailFace(ctx);
|
|
drawRail(ctx);
|
|
drawWood(ctx);
|
|
drawFelt(ctx);
|
|
drawDealer(ctx);
|
|
scene.textures.addCanvas('he-table', c);
|
|
}
|