Download code/ds_tr-clock/textures.js from Mike0021/inkling-mini-phaseA-3d-scenes: direct link, hf CLI and curl.
- Browser
- Download file 24 kB
-
https://huggingface.co/datasets/Mike0021/inkling-mini-phaseA-3d-scenes/resolve/main/code/ds_tr-clock/textures.js
- Command line
-
hf download hf://datasets/Mike0021/inkling-mini-phaseA-3d-scenes/code/ds_tr-clock/textures.js
-
curl -L -o textures.js https://huggingface.co/datasets/Mike0021/inkling-mini-phaseA-3d-scenes/resolve/main/code/ds_tr-clock/textures.js
24 kB
| import * as THREE from 'three'; | |
| /* -------- small deterministic RNG -------- */ | |
| export function rng(seed = 1) { | |
| let a = seed >>> 0; | |
| return function () { | |
| a |= 0; a = (a + 0x6D2B79F5) | 0; | |
| let t = Math.imul(a ^ (a >>> 15), 1 | a); | |
| t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; | |
| return ((t ^ (t >>> 14)) >>> 0) / 4294967296; | |
| }; | |
| } | |
| function makeCanvas(w, h) { | |
| const c = document.createElement('canvas'); | |
| c.width = w; c.height = h; | |
| return [c, c.getContext('2d')]; | |
| } | |
| export function texFromCanvas(c, { srgb = true, repeat = [1, 1], aniso = 8 } = {}) { | |
| const t = new THREE.CanvasTexture(c); | |
| t.wrapS = t.wrapT = THREE.RepeatWrapping; | |
| t.repeat.set(repeat[0], repeat[1]); | |
| t.anisotropy = aniso; | |
| if (srgb) t.colorSpace = THREE.SRGBColorSpace; | |
| t.needsUpdate = true; | |
| return t; | |
| } | |
| /* -------- mahogany / case wood -------- */ | |
| function drawGrain(ctx, W, H, r, opts = {}) { | |
| const { dark = '#3a160c', light = '#8c4527', lines = 150, vertical = true } = opts; | |
| ctx.save(); | |
| if (vertical) ctx.translate(W / 2, H / 2), ctx.rotate(0); | |
| for (let i = 0; i < lines; i++) { | |
| const x = r() * W; | |
| const amp = 2 + r() * 12; | |
| const freq = 0.006 + r() * 0.02; | |
| const phase = r() * Math.PI * 2; | |
| const alpha = 0.04 + r() * 0.13; | |
| ctx.strokeStyle = r() > 0.45 ? dark : light; | |
| ctx.globalAlpha = alpha; | |
| ctx.lineWidth = 0.6 + r() * 2.2; | |
| ctx.beginPath(); | |
| for (let y = -20; y <= H + 20; y += 8) { | |
| const xx = x + Math.sin(y * freq + phase) * amp + Math.sin(y * freq * 2.7 + phase) * amp * 0.3; | |
| if (y === -20) ctx.moveTo(xx, y); else ctx.lineTo(xx, y); | |
| } | |
| ctx.stroke(); | |
| } | |
| // knots / figure | |
| const knots = opts.knots ?? 5; | |
| for (let k = 0; k < knots; k++) { | |
| const kx = r() * W, ky = r() * H, kr = 8 + r() * 26; | |
| const g = ctx.createRadialGradient(kx, ky, 1, kx, ky, kr * 2.4); | |
| g.addColorStop(0, 'rgba(30,10,4,0.55)'); | |
| g.addColorStop(0.35, 'rgba(55,20,8,0.30)'); | |
| g.addColorStop(0.7, 'rgba(120,60,30,0.10)'); | |
| g.addColorStop(1, 'rgba(0,0,0,0)'); | |
| ctx.globalAlpha = 1; ctx.fillStyle = g; | |
| ctx.beginPath(); ctx.ellipse(kx, ky, kr, kr * 2.1, 0, 0, Math.PI * 2); ctx.fill(); | |
| ctx.strokeStyle = 'rgba(35,12,5,0.35)'; ctx.lineWidth = 1; | |
| for (let i = 0; i < 4; i++) { | |
| ctx.beginPath(); | |
| ctx.ellipse(kx, ky, kr * (0.5 + i * 0.45), kr * 2.0 * (0.45 + i * 0.42), 0, 0, Math.PI * 2); | |
| ctx.stroke(); | |
| } | |
| } | |
| // broad tonal cloudiness | |
| for (let i = 0; i < 26; i++) { | |
| const x = r() * W, y = r() * H, rad = 40 + r() * 200; | |
| const g = ctx.createRadialGradient(x, y, 0, x, y, rad); | |
| g.addColorStop(0, r() > 0.5 ? 'rgba(150,80,40,0.07)' : 'rgba(25,8,3,0.10)'); | |
| g.addColorStop(1, 'rgba(0,0,0,0)'); | |
| ctx.globalAlpha = 1; ctx.fillStyle = g; | |
| ctx.fillRect(x - rad, y - rad, rad * 2, rad * 2); | |
| } | |
| ctx.restore(); | |
| } | |
| export function makeMahogany(seed = 7) { | |
| const r = rng(seed); | |
| const [c, ctx] = makeCanvas(1024, 1024); | |
| const g = ctx.createLinearGradient(0, 0, 1024, 0); | |
| g.addColorStop(0, '#35160c'); | |
| g.addColorStop(0.35, '#512412'); | |
| g.addColorStop(0.6, '#421c0e'); | |
| g.addColorStop(1, '#2b0f07'); | |
| ctx.fillStyle = g; ctx.fillRect(0, 0, 1024, 1024); | |
| drawGrain(ctx, 1024, 1024, r, { dark: '#240a05', light: '#8e4420', lines: 230, knots: 6 }); | |
| // subtle french polish sheen | |
| const sheen = ctx.createLinearGradient(0, 0, 1024, 1024); | |
| sheen.addColorStop(0, 'rgba(255,190,120,0.06)'); | |
| sheen.addColorStop(0.5, 'rgba(255,255,255,0)'); | |
| sheen.addColorStop(1, 'rgba(0,0,0,0.10)'); | |
| ctx.fillStyle = sheen; ctx.fillRect(0, 0, 1024, 1024); | |
| // bump | |
| const [bc, bctx] = makeCanvas(512, 512); | |
| bctx.fillStyle = '#808080'; bctx.fillRect(0, 0, 512, 512); | |
| const br = rng(seed + 3); | |
| drawGrain(bctx, 512, 512, br, { dark: '#4a4a4a', light: '#b0b0b0', lines: 170, knots: 5 }); | |
| // roughness | |
| const [rc, rctx] = makeCanvas(512, 512); | |
| rctx.fillStyle = '#7d7d7d'; rctx.fillRect(0, 0, 512, 512); | |
| const rr = rng(seed + 9); | |
| for (let i = 0; i < 300; i++) { | |
| const x = rr() * 512, y = rr() * 512, rad = 4 + rr() * 60; | |
| const gg = rctx.createRadialGradient(x, y, 0, x, y, rad); | |
| const v = 90 + Math.floor(rr() * 90); | |
| gg.addColorStop(0, `rgba(${v},${v},${v},0.28)`); | |
| gg.addColorStop(1, 'rgba(0,0,0,0)'); | |
| rctx.fillStyle = gg; rctx.fillRect(x - rad, y - rad, rad * 2, rad * 2); | |
| } | |
| return { | |
| map: texFromCanvas(c, { repeat: [1, 1] }), | |
| bumpMap: texFromCanvas(bc, { srgb: false }), | |
| roughnessMap: texFromCanvas(rc, { srgb: false }), | |
| }; | |
| } | |
| /* -------- polished walnut plank floor -------- */ | |
| export function makeFloor(seed = 21) { | |
| const W = 1024, H = 1024; | |
| const r = rng(seed); | |
| const [c, ctx] = makeCanvas(W, H); | |
| ctx.fillStyle = '#2a150b'; ctx.fillRect(0, 0, W, H); | |
| const cols = 8, pw = W / cols; | |
| for (let i = 0; i < cols; i++) { | |
| const shade = 0.82 + r() * 0.4; | |
| const base = [63 * shade, 36 * shade, 20 * shade]; | |
| const g = ctx.createLinearGradient(i * pw, 0, (i + 1) * pw, 0); | |
| g.addColorStop(0, `rgb(${base[0] * 0.72},${base[1] * 0.7},${base[2] * 0.65})`); | |
| g.addColorStop(0.15, `rgb(${base[0]},${base[1]},${base[2]})`); | |
| g.addColorStop(0.55, `rgb(${base[0] * 1.18},${base[1] * 1.16},${base[2] * 1.1})`); | |
| g.addColorStop(1, `rgb(${base[0] * 0.72},${base[1] * 0.7},${base[2] * 0.65})`); | |
| ctx.fillStyle = g; | |
| ctx.fillRect(i * pw + 1, 0, pw - 2, H); | |
| // plank joints (staggered) | |
| const off = (i % 2) * H * 0.5 + Math.floor(r() * H * 0.3); | |
| ctx.fillStyle = 'rgba(8,3,1,0.9)'; | |
| for (let k = 0; k < 2; k++) { | |
| const yy = (off + k * H * 0.5) % H; | |
| ctx.fillRect(i * pw + 1, yy, pw - 2, 3); | |
| ctx.fillStyle = 'rgba(190,130,80,0.18)'; | |
| ctx.fillRect(i * pw + 1, yy + 3, pw - 2, 1); | |
| ctx.fillStyle = 'rgba(8,3,1,0.9)'; | |
| } | |
| // grain along plank | |
| ctx.save(); | |
| ctx.beginPath(); ctx.rect(i * pw, 0, pw, H); ctx.clip(); | |
| for (let j = 0; j < 46; j++) { | |
| const x = i * pw + r() * pw; | |
| ctx.strokeStyle = r() > 0.5 ? 'rgba(24,9,4,0.30)' : 'rgba(160,95,50,0.14)'; | |
| ctx.lineWidth = 0.6 + r() * 1.7; | |
| ctx.beginPath(); | |
| const amp = 1 + r() * 5, ph = r() * 6.28, fr = 0.004 + r() * 0.012; | |
| for (let y = 0; y <= H; y += 10) { | |
| const xx = x + Math.sin(y * fr + ph) * amp; | |
| if (y === 0) ctx.moveTo(xx, y); else ctx.lineTo(xx, y); | |
| } | |
| ctx.stroke(); | |
| } | |
| ctx.restore(); | |
| } | |
| // worn polish highlights | |
| for (let i = 0; i < 70; i++) { | |
| const x = r() * W, y = r() * H, rad = 20 + r() * 110; | |
| const g = ctx.createRadialGradient(x, y, 0, x, y, rad); | |
| g.addColorStop(0, 'rgba(255,205,140,0.07)'); | |
| g.addColorStop(1, 'rgba(0,0,0,0)'); | |
| ctx.fillStyle = g; ctx.fillRect(x - rad, y - rad, rad * 2, rad * 2); | |
| } | |
| // bump | |
| const [bc, bctx] = makeCanvas(512, 512); | |
| bctx.fillStyle = '#808080'; bctx.fillRect(0, 0, 512, 512); | |
| const br = rng(seed + 5); | |
| for (let i = 0; i < 8; i++) { | |
| bctx.fillStyle = '#3c3c3c'; | |
| bctx.fillRect(i * 64, 0, 2, 512); | |
| } | |
| for (let i = 0; i < 700; i++) { | |
| bctx.strokeStyle = br() > 0.5 ? 'rgba(30,30,30,0.18)' : 'rgba(210,210,210,0.12)'; | |
| bctx.lineWidth = 0.6 + br() * 1.3; | |
| const x = br() * 512; | |
| bctx.beginPath(); bctx.moveTo(x, 0); bctx.bezierCurveTo(x + 4, 170, x - 4, 340, x + 2, 512); bctx.stroke(); | |
| } | |
| // roughness: polished with variation | |
| const [rc, rctx] = makeCanvas(512, 512); | |
| rctx.fillStyle = '#4b4b4b'; rctx.fillRect(0, 0, 512, 512); | |
| const rr = rng(seed + 11); | |
| for (let i = 0; i < 220; i++) { | |
| const x = rr() * 512, y = rr() * 512, rad = 10 + rr() * 80; | |
| const g = rctx.createRadialGradient(x, y, 0, x, y, rad); | |
| const v = 40 + Math.floor(rr() * 80); | |
| g.addColorStop(0, `rgba(${v},${v},${v},0.5)`); | |
| g.addColorStop(1, 'rgba(0,0,0,0)'); | |
| rctx.fillStyle = g; rctx.fillRect(x - rad, y - rad, rad * 2, rad * 2); | |
| } | |
| return { | |
| map: texFromCanvas(c, { repeat: [5, 5] }), | |
| bumpMap: texFromCanvas(bc, { srgb: false, repeat: [5, 5] }), | |
| roughnessMap: texFromCanvas(rc, { srgb: false, repeat: [5, 5] }), | |
| }; | |
| } | |
| /* -------- painted wainscot / cream joinery -------- */ | |
| export function makePaintedWood(seed = 31, base = '#cfc0a0') { | |
| const r = rng(seed); | |
| const [c, ctx] = makeCanvas(512, 512); | |
| ctx.fillStyle = base; ctx.fillRect(0, 0, 512, 512); | |
| for (let i = 0; i < 120; i++) { | |
| ctx.strokeStyle = r() > 0.5 ? 'rgba(90,72,48,0.06)' : 'rgba(255,255,240,0.05)'; | |
| ctx.lineWidth = 0.5 + r() * 1.5; | |
| const x = r() * 512; | |
| ctx.beginPath(); | |
| for (let y = 0; y <= 512; y += 12) { | |
| const xx = x + Math.sin(y * 0.01 + r() * 0.2) * (1 + r() * 2); | |
| if (y === 0) ctx.moveTo(xx, y); else ctx.lineTo(xx, y); | |
| } | |
| ctx.stroke(); | |
| } | |
| // age / wear around edges | |
| const grd = ctx.createLinearGradient(0, 0, 0, 512); | |
| grd.addColorStop(0, 'rgba(255,250,230,0.05)'); | |
| grd.addColorStop(1, 'rgba(60,45,25,0.10)'); | |
| ctx.fillStyle = grd; ctx.fillRect(0, 0, 512, 512); | |
| const [bc, bctx] = makeCanvas(256, 256); | |
| bctx.fillStyle = '#808080'; bctx.fillRect(0, 0, 256, 256); | |
| const br = rng(seed + 2); | |
| for (let i = 0; i < 400; i++) { | |
| bctx.strokeStyle = br() > 0.5 ? 'rgba(150,150,150,0.25)' : 'rgba(110,110,110,0.2)'; | |
| bctx.lineWidth = 0.6 + br(); | |
| const x = br() * 256; | |
| bctx.beginPath(); bctx.moveTo(x, 0); bctx.lineTo(x + br() * 4 - 2, 256); bctx.stroke(); | |
| } | |
| return { | |
| map: texFromCanvas(c, { repeat: [1, 1] }), | |
| bumpMap: texFromCanvas(bc, { srgb: false }), | |
| }; | |
| } | |
| /* -------- damask wallpaper -------- */ | |
| export function makeWallpaper(seed = 41) { | |
| const S = 512; | |
| const r = rng(seed); | |
| const [c, ctx] = makeCanvas(S, S); | |
| const g = ctx.createLinearGradient(0, 0, 0, S); | |
| g.addColorStop(0, '#1a2a23'); | |
| g.addColorStop(1, '#101c17'); | |
| ctx.fillStyle = g; ctx.fillRect(0, 0, S, S); | |
| // fine vertical silk stripes | |
| for (let x = 0; x < S; x += 4) { | |
| ctx.fillStyle = x % 8 === 0 ? 'rgba(120,150,125,0.035)' : 'rgba(0,0,0,0.025)'; | |
| ctx.fillRect(x, 0, 2, S); | |
| } | |
| // damask motif | |
| const drawMotif = (cx, cy, s, alpha) => { | |
| ctx.save(); ctx.translate(cx, cy); ctx.scale(s, s); | |
| ctx.globalAlpha = alpha; | |
| ctx.strokeStyle = 'rgba(150,132,92,0.75)'; ctx.fillStyle = 'rgba(150,132,92,0.13)'; | |
| ctx.lineWidth = 1.2; | |
| // central fleur | |
| ctx.beginPath(); | |
| ctx.moveTo(0, -42); | |
| ctx.bezierCurveTo(16, -22, 10, -8, 0, 4); | |
| ctx.bezierCurveTo(-10, -8, -16, -22, 0, -42); | |
| ctx.fill(); ctx.stroke(); | |
| for (const sgn of [-1, 1]) { | |
| ctx.beginPath(); | |
| ctx.moveTo(0, -12); | |
| ctx.bezierCurveTo(30 * sgn, -30, 46 * sgn, -2, 20 * sgn, 16); | |
| ctx.bezierCurveTo(26 * sgn, 30, 14 * sgn, 46, 0, 54); | |
| ctx.stroke(); | |
| // leaf curls | |
| ctx.beginPath(); | |
| ctx.ellipse(38 * sgn, -10, 6, 15, 0.6 * sgn, 0, Math.PI * 2); | |
| ctx.fill(); ctx.stroke(); | |
| ctx.beginPath(); | |
| ctx.ellipse(22 * sgn, 34, 5, 12, -0.5 * sgn, 0, Math.PI * 2); | |
| ctx.fill(); ctx.stroke(); | |
| } | |
| // base curls | |
| ctx.beginPath(); | |
| ctx.moveTo(-18, 62); ctx.bezierCurveTo(-6, 50, 6, 50, 18, 62); | |
| ctx.stroke(); | |
| ctx.restore(); | |
| }; | |
| // half-drop repeat | |
| drawMotif(S * 0.25, S * 0.25, 0.95, 0.55); | |
| drawMotif(S * 0.75, S * 0.25, 0.95, 0.55); | |
| drawMotif(S * 0.5, S * 0.75, 1.05, 0.6); | |
| drawMotif(S * 0.0, S * 0.75, 0.6, 0.35); | |
| drawMotif(S * 1.0, S * 0.75, 0.6, 0.35); | |
| // aged mottling | |
| for (let i = 0; i < 120; i++) { | |
| const x = r() * S, y = r() * S, rad = 10 + r() * 70; | |
| const gg = ctx.createRadialGradient(x, y, 0, x, y, rad); | |
| gg.addColorStop(0, r() > 0.5 ? 'rgba(0,0,0,0.10)' : 'rgba(170,160,120,0.05)'); | |
| gg.addColorStop(1, 'rgba(0,0,0,0)'); | |
| ctx.fillStyle = gg; ctx.fillRect(x - rad, y - rad, rad * 2, rad * 2); | |
| } | |
| const [bc, bctx] = makeCanvas(256, 256); | |
| bctx.fillStyle = '#808080'; bctx.fillRect(0, 0, 256, 256); | |
| const br = rng(seed + 6); | |
| for (let i = 0; i < 250; i++) { | |
| bctx.fillStyle = br() > 0.5 ? 'rgba(160,160,160,0.25)' : 'rgba(100,100,100,0.2)'; | |
| bctx.fillRect(br() * 256, br() * 256, 1 + br() * 4, 1 + br() * 4); | |
| } | |
| return { | |
| map: texFromCanvas(c, { repeat: [3, 2.4] }), | |
| bumpMap: texFromCanvas(bc, { srgb: false, repeat: [3, 2.4] }), | |
| }; | |
| } | |
| /* -------- dial face -------- */ | |
| export function makeDial(seed = 53) { | |
| const S = 1024, cx = S / 2, cy = S / 2; | |
| const r = rng(seed); | |
| const [c, ctx] = makeCanvas(S, S); | |
| ctx.clearRect(0, 0, S, S); | |
| // face | |
| const faceR = 505; | |
| const g = ctx.createRadialGradient(cx - 100, cy - 130, 20, cx, cy, faceR); | |
| g.addColorStop(0, '#f4ecd8'); | |
| g.addColorStop(0.55, '#e9ddc1'); | |
| g.addColorStop(0.85, '#d8c8a6'); | |
| g.addColorStop(1, '#c0ac86'); | |
| ctx.fillStyle = g; | |
| ctx.beginPath(); ctx.arc(cx, cy, faceR, 0, Math.PI * 2); ctx.fill(); | |
| // age stains | |
| for (let i = 0; i < 230; i++) { | |
| const a = r() * Math.PI * 2, rad = Math.sqrt(r()) * faceR; | |
| const x = cx + Math.cos(a) * rad, y = cy + Math.sin(a) * rad; | |
| const rr = 1 + r() * 22; | |
| const gg = ctx.createRadialGradient(x, y, 0, x, y, rr); | |
| gg.addColorStop(0, r() > 0.3 ? 'rgba(120,88,45,0.10)' : 'rgba(255,255,240,0.16)'); | |
| gg.addColorStop(1, 'rgba(0,0,0,0)'); | |
| ctx.fillStyle = gg; ctx.fillRect(x - rr, y - rr, rr * 2, rr * 2); | |
| } | |
| // outer brass/black rim | |
| ctx.strokeStyle = '#3a2a18'; ctx.lineWidth = 14; | |
| ctx.beginPath(); ctx.arc(cx, cy, 490, 0, Math.PI * 2); ctx.stroke(); | |
| ctx.strokeStyle = 'rgba(150,120,70,0.5)'; ctx.lineWidth = 3; | |
| ctx.beginPath(); ctx.arc(cx, cy, 498, 0, Math.PI * 2); ctx.stroke(); | |
| // chapter ring | |
| const rOut = 452, rIn = 365, rNum = 414; | |
| ctx.strokeStyle = '#2a1d10'; | |
| ctx.lineWidth = 5; | |
| ctx.beginPath(); ctx.arc(cx, cy, rOut, 0, Math.PI * 2); ctx.stroke(); | |
| ctx.lineWidth = 3; | |
| ctx.beginPath(); ctx.arc(cx, cy, rIn, 0, Math.PI * 2); ctx.stroke(); | |
| ctx.lineWidth = 1.5; | |
| ctx.beginPath(); ctx.arc(cx, cy, rOut - 10, 0, Math.PI * 2); ctx.stroke(); | |
| ctx.beginPath(); ctx.arc(cx, cy, rIn + 8, 0, Math.PI * 2); ctx.stroke(); | |
| // minute ticks | |
| for (let i = 0; i < 60; i++) { | |
| const a = (i / 60) * Math.PI * 2; | |
| const major = i % 5 === 0; | |
| const r1 = major ? 397 : 420, r2 = 445; | |
| ctx.strokeStyle = major ? '#241708' : '#4a3822'; | |
| ctx.lineWidth = major ? 6 : 2.2; | |
| ctx.beginPath(); | |
| ctx.moveTo(cx + Math.cos(a) * r1, cy + Math.sin(a) * r1); | |
| ctx.lineTo(cx + Math.cos(a) * r2, cy + Math.sin(a) * r2); | |
| ctx.stroke(); | |
| } | |
| // roman numerals | |
| const roman = ['XII', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI']; | |
| ctx.fillStyle = '#241708'; | |
| ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; | |
| ctx.font = 'bold 66px Georgia, "Times New Roman", serif'; | |
| for (let i = 0; i < 12; i++) { | |
| if (i === 0 || i === 6) continue; // XII covered by moon window, VI by subdial | |
| const a = -Math.PI / 2 + (i / 12) * Math.PI * 2; | |
| const x = cx + Math.cos(a) * rNum, y = cy + Math.sin(a) * rNum; | |
| ctx.save(); ctx.translate(x, y); ctx.rotate(a + Math.PI / 2); | |
| ctx.fillText(roman[i], 0, 0); | |
| ctx.restore(); | |
| } | |
| // XII tucked high | |
| ctx.font = 'bold 52px Georgia, serif'; | |
| ctx.fillText('XII', cx, cy - rNum - 2); | |
| // gilt inner ornaments | |
| ctx.strokeStyle = 'rgba(150,112,50,0.75)'; | |
| ctx.lineWidth = 2; | |
| for (let i = 0; i < 12; i++) { | |
| const a = -Math.PI / 2 + (i / 12) * Math.PI * 2; | |
| const x = cx + Math.cos(a) * 345, y = cy + Math.sin(a) * 345; | |
| ctx.save(); ctx.translate(x, y); | |
| ctx.beginPath(); | |
| ctx.moveTo(0, -5); ctx.bezierCurveTo(10, -20, 24, 4, 6, 10); | |
| ctx.bezierCurveTo(-2, 17, -14, 10, -9, 1); | |
| ctx.stroke(); | |
| ctx.restore(); | |
| } | |
| // engraved flourishes at diagonals | |
| const flourish = (fx, fy, rot, s) => { | |
| ctx.save(); ctx.translate(fx, fy); ctx.rotate(rot); ctx.scale(s, s); | |
| ctx.strokeStyle = 'rgba(160,120,55,0.8)'; ctx.lineWidth = 2.5; | |
| for (let k = 0; k < 3; k++) { | |
| ctx.beginPath(); | |
| ctx.moveTo(0, 24 + k * 8); | |
| ctx.bezierCurveTo(40 + k * 10, 6 + k * 10, 55 - k * 4, -18 - k * 8, 20 + k * 6, -30 - k * 10); | |
| ctx.stroke(); | |
| } | |
| ctx.beginPath(); ctx.arc(17, -31, 4, 0, Math.PI * 2); ctx.fillStyle = 'rgba(160,120,55,0.8)'; ctx.fill(); | |
| ctx.restore(); | |
| }; | |
| flourish(cx - 240, cy - 220, -0.5, 1.0); | |
| flourish(cx + 240, cy - 220, 0.5 + Math.PI, 1.0); | |
| flourish(cx - 240, cy + 220, -2.2, 0.9); | |
| flourish(cx + 240, cy + 220, 2.2, 0.9); | |
| // maker text | |
| ctx.fillStyle = '#3a2a16'; | |
| ctx.font = '30px Georgia, serif'; | |
| ctx.textAlign = 'center'; | |
| ctx.fillText('R · WYNDHAM', cx, cy + 96); | |
| ctx.font = 'italic 22px Georgia, serif'; | |
| ctx.fillStyle = '#5a4525'; | |
| ctx.fillText('LONDON', cx, cy + 126); | |
| // seconds subdial | |
| const sy = cy + 220, sr = 78; | |
| const sg = ctx.createRadialGradient(cx - 20, sy - 20, 4, cx, sy, sr); | |
| sg.addColorStop(0, '#f3ebd7'); sg.addColorStop(1, '#dcccaa'); | |
| ctx.fillStyle = sg; | |
| ctx.beginPath(); ctx.arc(cx, sy, sr, 0, Math.PI * 2); ctx.fill(); | |
| ctx.strokeStyle = '#3a2a16'; ctx.lineWidth = 3; | |
| ctx.beginPath(); ctx.arc(cx, sy, sr, 0, Math.PI * 2); ctx.stroke(); | |
| ctx.beginPath(); ctx.arc(cx, sy, sr - 7, 0, Math.PI * 2); ctx.stroke(); | |
| for (let i = 0; i < 60; i++) { | |
| const a = (i / 60) * Math.PI * 2; | |
| const major = i % 5 === 0; | |
| ctx.strokeStyle = '#3a2a16'; ctx.lineWidth = major ? 3 : 1; | |
| const r1 = major ? sr - 20 : sr - 12; | |
| ctx.beginPath(); | |
| ctx.moveTo(cx + Math.cos(a) * r1, sy + Math.sin(a) * r1); | |
| ctx.lineTo(cx + Math.cos(a) * (sr - 7), sy + Math.sin(a) * (sr - 7)); | |
| ctx.stroke(); | |
| } | |
| for (let i = 0; i < 12; i++) { | |
| const a = (i / 12) * Math.PI * 2; | |
| ctx.fillStyle = '#3a2a16'; ctx.font = 'bold 18px Georgia, serif'; | |
| ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; | |
| ctx.fillText(String(i * 5), cx + Math.cos(a) * (sr - 34), sy + Math.sin(a) * (sr - 34)); | |
| } | |
| // hairline cracks | |
| ctx.strokeStyle = 'rgba(80,55,25,0.18)'; ctx.lineWidth = 1; | |
| for (let i = 0; i < 12; i++) { | |
| const a = r() * 6.28, rad = 100 + r() * 330; | |
| ctx.beginPath(); | |
| ctx.moveTo(cx + Math.cos(a) * rad, cy + Math.sin(a) * rad); | |
| for (let k = 1; k < 7; k++) { | |
| const aa = a + (r() - 0.5) * 0.3, rr = rad + k * 12; | |
| ctx.lineTo(cx + Math.cos(aa) * rr, cy + Math.sin(aa) * rr); | |
| } | |
| ctx.stroke(); | |
| } | |
| return { map: texFromCanvas(c, { repeat: [1, 1], aniso: 16 }), canvas: c }; | |
| } | |
| /* -------- moon phase disc -------- */ | |
| export function makeMoon(seed = 61) { | |
| const S = 512, cx = 256, cy = 256; | |
| const r = rng(seed); | |
| const [c, ctx] = makeCanvas(S, S); | |
| const g = ctx.createRadialGradient(cx, cy, 10, cx, cy, 256); | |
| g.addColorStop(0, '#1d3b5e'); | |
| g.addColorStop(0.6, '#122943'); | |
| g.addColorStop(1, '#091627'); | |
| ctx.fillStyle = g; ctx.beginPath(); ctx.arc(cx, cy, 256, 0, Math.PI * 2); ctx.fill(); | |
| // stars | |
| for (let i = 0; i < 90; i++) { | |
| const a = r() * Math.PI * 2, rad = Math.sqrt(r()) * 245; | |
| const x = cx + Math.cos(a) * rad, y = cy + Math.sin(a) * rad; | |
| const s = 0.5 + r() * 1.8; | |
| ctx.fillStyle = `rgba(${210 + r() * 45},${215 + r() * 40},${200 + r() * 55},${0.4 + r() * 0.6})`; | |
| ctx.beginPath(); ctx.arc(x, y, s, 0, Math.PI * 2); ctx.fill(); | |
| } | |
| // crescent moon with maria | |
| const mx = cx + 64, my = cy - 58, mr = 100; | |
| const mg = ctx.createRadialGradient(mx - 30, my - 30, 8, mx, my, mr); | |
| mg.addColorStop(0, '#fff8dc'); | |
| mg.addColorStop(0.7, '#e8d9a8'); | |
| mg.addColorStop(1, '#b9a878'); | |
| ctx.fillStyle = mg; | |
| ctx.beginPath(); ctx.arc(mx, my, mr, 0, Math.PI * 2); ctx.fill(); | |
| ctx.fillStyle = 'rgba(130,115,85,0.26)'; | |
| const maria = []; | |
| for (let i = 0; i < 16; i++) { | |
| const a = r() * 6.28, rad = Math.sqrt(r()) * mr * 0.75; | |
| const x = mx + Math.cos(a) * rad, y = my + Math.sin(a) * rad; | |
| const ex = 5 + r() * 18, ey = 4 + r() * 13, er = r() * 3; | |
| ctx.beginPath(); ctx.ellipse(x, y, ex, ey, er, 0, Math.PI * 2); ctx.fill(); | |
| maria.push([x, y, ex, ey, er]); | |
| } | |
| // carve a crescent shadow | |
| ctx.save(); | |
| ctx.globalCompositeOperation = 'source-over'; | |
| const cg = ctx.createRadialGradient(mx + 44, my - 22, 20, mx + 44, my - 22, mr * 1.05); | |
| cg.addColorStop(0, '#122943'); | |
| cg.addColorStop(0.8, '#122943'); | |
| cg.addColorStop(1, 'rgba(18,41,67,0)'); | |
| ctx.fillStyle = cg; | |
| ctx.beginPath(); ctx.arc(mx + 62, my - 26, mr * 0.96, 0, Math.PI * 2); ctx.fill(); | |
| ctx.restore(); | |
| // halo | |
| const hg = ctx.createRadialGradient(mx, my, mr * 0.9, mx, my, mr * 1.5); | |
| hg.addColorStop(0, 'rgba(255,235,170,0.20)'); | |
| hg.addColorStop(1, 'rgba(255,235,170,0)'); | |
| ctx.fillStyle = hg; | |
| ctx.beginPath(); ctx.arc(mx, my, mr * 1.5, 0, Math.PI * 2); ctx.fill(); | |
| // second faint moon for phase cycling | |
| ctx.fillStyle = 'rgba(230,225,200,0.18)'; | |
| ctx.beginPath(); ctx.arc(cx - 110, cy + 75, 34, 0, Math.PI * 2); ctx.fill(); | |
| return { map: texFromCanvas(c, { repeat: [1, 1], aniso: 16 }) }; | |
| } | |
| /* -------- aged brass -------- */ | |
| export function makeBrassMaps(seed = 71) { | |
| const S = 512; | |
| const r = rng(seed); | |
| const [c, ctx] = makeCanvas(S, S); | |
| ctx.fillStyle = '#c9a248'; ctx.fillRect(0, 0, S, S); | |
| for (let i = 0; i < 240; i++) { | |
| const x = r() * S, y = r() * S, rad = 6 + r() * 70; | |
| const g = ctx.createRadialGradient(x, y, 0, x, y, rad); | |
| g.addColorStop(0, r() > 0.45 ? 'rgba(120,80,30,0.25)' : 'rgba(255,235,170,0.30)'); | |
| g.addColorStop(1, 'rgba(0,0,0,0)'); | |
| ctx.fillStyle = g; ctx.fillRect(x - rad, y - rad, rad * 2, rad * 2); | |
| } | |
| const [rc, rctx] = makeCanvas(256, 256); | |
| rctx.fillStyle = '#585858'; rctx.fillRect(0, 0, 256, 256); | |
| const rr = rng(seed + 4); | |
| for (let i = 0; i < 220; i++) { | |
| const x = rr() * 256, y = rr() * 256, rad = 3 + rr() * 40; | |
| const g = rctx.createRadialGradient(x, y, 0, x, y, rad); | |
| const v = 50 + Math.floor(rr() * 120); | |
| g.addColorStop(0, `rgba(${v},${v},${v},0.5)`); | |
| g.addColorStop(1, 'rgba(0,0,0,0)'); | |
| rctx.fillStyle = g; rctx.fillRect(x - rad, y - rad, rad * 2, rad * 2); | |
| } | |
| return { | |
| map: texFromCanvas(c, { repeat: [2, 2] }), | |
| roughnessMap: texFromCanvas(rc, { srgb: false, repeat: [2, 2] }), | |
| }; | |
| } | |
| /* -------- soft round contact shadow -------- */ | |
| export function makeShadowTexture() { | |
| const S = 256; | |
| const [c, ctx] = makeCanvas(S, S); | |
| const g = ctx.createRadialGradient(128, 128, 8, 128, 128, 124); | |
| g.addColorStop(0, 'rgba(0,0,0,0.72)'); | |
| g.addColorStop(0.4, 'rgba(0,0,0,0.45)'); | |
| g.addColorStop(0.75, 'rgba(0,0,0,0.14)'); | |
| g.addColorStop(1, 'rgba(0,0,0,0)'); | |
| ctx.fillStyle = g; ctx.fillRect(0, 0, S, S); | |
| return texFromCanvas(c, { srgb: false }); | |
| } | |
| /* -------- sky gradient -------- */ | |
| export function makeSkyTexture() { | |
| const W = 32, H = 512; | |
| const [c, ctx] = makeCanvas(W, H); | |
| const g = ctx.createLinearGradient(0, 0, 0, H); | |
| g.addColorStop(0, '#0a1119'); | |
| g.addColorStop(0.45, '#131a1c'); | |
| g.addColorStop(0.62, '#2b241c'); | |
| g.addColorStop(0.8, '#3a2a1d'); | |
| g.addColorStop(1, '#0d0a07'); | |
| ctx.fillStyle = g; ctx.fillRect(0, 0, W, H); | |
| return texFromCanvas(c, { repeat: [1, 1] }); | |
| } | |
| /* -------- small engraved brass plaque -------- */ | |
| export function makePlaque() { | |
| const W = 512, H = 128; | |
| const [c, ctx] = makeCanvas(W, H); | |
| const g = ctx.createLinearGradient(0, 0, 0, H); | |
| g.addColorStop(0, '#d8b766'); | |
| g.addColorStop(0.5, '#a9803a'); | |
| g.addColorStop(1, '#c9a754'); | |
| ctx.fillStyle = g; ctx.fillRect(0, 0, W, H); | |
| ctx.strokeStyle = 'rgba(60,35,8,0.85)'; ctx.lineWidth = 5; | |
| ctx.strokeRect(8, 8, W - 16, H - 16); | |
| ctx.strokeStyle = 'rgba(255,235,180,0.55)'; ctx.lineWidth = 2; | |
| ctx.strokeRect(14, 14, W - 28, H - 28); | |
| ctx.fillStyle = '#3a2508'; | |
| ctx.font = 'bold 46px Georgia, serif'; | |
| ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; | |
| ctx.fillText('TEMPUS FUGIT', W / 2, H / 2 + 2); | |
| return texFromCanvas(c, { repeat: [1, 1], aniso: 8 }); | |
| } | |
| /* -------- soft floor falloff / vignette -------- */ | |
| export function makeFloorFade() { | |
| const S = 512; | |
| const [c, ctx] = makeCanvas(S, S); | |
| const g = ctx.createRadialGradient(S / 2, S / 2, S * 0.12, S / 2, S / 2, S * 0.5); | |
| g.addColorStop(0, 'rgba(0,0,0,0)'); | |
| g.addColorStop(0.42, 'rgba(0,0,0,0.06)'); | |
| g.addColorStop(0.68, 'rgba(0,0,0,0.38)'); | |
| g.addColorStop(0.88, 'rgba(0,0,0,0.72)'); | |
| g.addColorStop(1, 'rgba(0,0,0,0.92)'); | |
| ctx.fillStyle = g; ctx.fillRect(0, 0, S, S); | |
| return texFromCanvas(c, { srgb: false }); | |
| } | |