Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Add Pottery Wheel: centre the clay and pull the tallest pot without tearing it #27
Check · Review · Land · Live done — Landed and live in production.
quill/pixel-plays:quill/24-add-pottery-wheel-centre-the-clay-and-pu → main 3 commits fork 3 threads · 3 unresolved
7 files
changed +663
−1
README.md +2 −1
| @@ -20,6 +20,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am | ||
| 20 | 20 | | [](pizza-toss/) | Five tosses of pizza dough: hold to spin, catch it before it drops, too much spin tears it (forged by the crew on the engine and shell above, not by the original creators) | Hold and release, tap to catch; space | |
| 21 | 21 | | [](harbour-crane/) | Stack ten crates onto a bobbing fishing boat from a swinging crane hook; one hanging more than half off tips into the water (forged by the crew on the engine and shell above, not by the original creators) | Tap; space | |
| 22 | 22 | | [](sled-run/) | Ride a sledge down a snowy hill for 40 seconds: tuck for speed, release on a kicker to jump, land flat for points and nose-down to tumble (forged by the crew on the engine and shell above, not by the original creators) | Hold and release; space | |
| 23 | | [](pottery-wheel/) | Three pots on a kick wheel: hold to centre the clay without pressing too hard, then pull the wall up, too fast tears it and too slow slumps, and each pot has 40 seconds (clay still being centred then dries and is lost, a pull is fired as it stands); the score is the total height in pixels (forged by the crew on the engine and shell above, not by the original creators) | Hold to press, drag up to pull; space, up arrow, F to fire | | |
| 23 | 24 | | [](row-home/) | Race a rowing boat across the river against a bot: stroke in rhythm with the glide, too early catches a crab, hold left or right to steer against the current (forged by the crew on the engine and shell above, not by the original creators) | Tap or space to stroke; hold left/right | |
| 24 | 25 | |
| 25 | 26 | ## Run |
| @@ -34,7 +35,7 @@ Then open http://127.0.0.1:5300/. `PORT` and `HOST` override the port and addres | ||
| 34 | 35 | On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. The app keeps no state, so it does not need `FORGE_APP_DATA`. `bun test` checks that the server answers every game page and track. |
| 35 | 36 | |
| 36 | 37 | ## Add a game |
| 37 | Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too). The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run and Row Home play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`. | |
| 38 | Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too). The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel and Row Home play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`. | |
| 38 | 39 | |
| 39 | 40 | - `shell.js` provides the game menu, the Rules popup, the credits and the background music. |
| 40 | 41 | - `engine.js` provides the camera, depth buffer, colour ramps, shadows, edges, figures, trees and wind as globals. |
index.html +1
| @@ -35,6 +35,7 @@ footer a { display: inline; padding: 0; font-weight: inherit; text-decoration: u | ||
| 35 | 35 | <li><a href="pizza-toss/">Pizza Toss</a><span>Five tosses of pizza dough: hold to spin, catch it before it drops, too much spin tears it</span><span>Game forged by the crew</span></li> |
| 36 | 36 | <li><a href="harbour-crane/">Harbour Crane</a><span>Stack ten crates onto a bobbing fishing boat from a swinging crane hook</span><span>Game forged by the crew</span></li> |
| 37 | 37 | <li><a href="sled-run/">Sled Run</a><span>Ride a sledge down a snowy hill: tuck for speed, release on a kicker to jump, land flat</span><span>Game forged by the crew</span></li> |
| 38 | <li><a href="pottery-wheel/">Pottery Wheel</a><span>Shape a pot on a kick wheel: hold to centre the clay without collapsing it, then pull the wall as tall as you can before it tears</span><span>Game forged by the crew</span></li> | |
| 38 | 39 | <li><a href="row-home/">Row Home</a><span>Race a rowing boat across the river against a bot: stroke in rhythm with the glide, too early catches a crab</span><span>Game forged by the crew</span></li> |
| 39 | 40 | </ul> |
| 40 | 41 | <footer>Concept by <a href="https://x.com/awwbhi2">abhi</a>. Game by <a href="https://x.com/AmirMushich">AmirMushich</a>. Visual reference for the style: shawn.'s <a href="https://x.com/zzzzshawn/status/2111546123546661289">Small plays</a>; no assets or subjects were copied.</footer> |
pottery-wheel/clay.js added +77
| @@ -0,0 +1,77 @@ | ||
| 1 | 'use strict'; | |
| 2 | // The rules of one pot: plain data in, plain data out, no DOM. The page draws what this decides. | |
| 3 | (function (root) { | |
| 4 | const POTS = 3; | |
| 5 | const TIME_LIMIT = 40; // seconds a pot may take; past it centring dries out and a pull is fired as it stands | |
| 6 | const MAX_HEIGHT = 72; // canvas pixels a wall can be pulled to; the pot fires itself there | |
| 7 | // centring: pressure is how hard the hands press, 0..1 | |
| 8 | const WOBBLE_START = .9; // 0 is dead centre, 1 is wildly off | |
| 9 | const CENTRED = .1; // wobble at or below this and the clay is centred | |
| 10 | const PRESS_RAMP = 1.4; // seconds of holding from no pressure to full pressure | |
| 11 | const PRESS_RELEASE = 2.5; // pressure lost per second once the hands let go | |
| 12 | const MIN_PRESS = .15; // lighter than this does nothing and the lump drifts | |
| 13 | const HARD_PRESS = .65; // harder than this on a wobbling lump collapses it | |
| 14 | const CALM = .3; // a lump this steady can take any pressure | |
| 15 | const DECAY = 3; // wobble decays by exp(-DECAY * pressure * seconds) | |
| 16 | const DRIFT = .08; // wobble regained per second with no pressure | |
| 17 | // pulling: rate is how fast the hands rise, 0..1 | |
| 18 | const PULL_SPEED = 60; // pixels of wall per second at rate 1 | |
| 19 | const MIN_RATE = .2; // slower than this and the wall slumps | |
| 20 | const SLUMP = 5; // pixels lost per second while slumping | |
| 21 | const THIN_BASE = .004; // wall thickness lost per pixel pulled, however gently | |
| 22 | const THIN_FAST = .1; // extra loss per pixel, scaled by rate cubed | |
| 23 | const TEAR_THICKNESS = .3; // a wall thinner than this tears | |
| 24 | ||
| 25 | const unit = v => (Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0); | |
| 26 | ||
| 27 | // wobble: where the lump starts, 0..1 (defaults to the usual off-centre lump) | |
| 28 | function newPot(wobble = WOBBLE_START) { | |
| 29 | return { phase: 'centre', wobble: Math.max(CENTRED * 2, unit(wobble)), pressure: 0, rate: 0, height: 0, thickness: 1, elapsed: 0 }; | |
| 30 | } | |
| 31 | ||
| 32 | // input: { press: boolean, pull: 0..1 }; returns the next pot, never mutates | |
| 33 | function step(pot, input, dt) { | |
| 34 | const p = { ...pot }; | |
| 35 | if (!Number.isFinite(dt) || dt <= 0) return p; | |
| 36 | p.elapsed += dt; | |
| 37 | const press = !!(input && input.press), pull = unit(input && input.pull); | |
| 38 | if (p.phase === 'centre') { | |
| 39 | p.pressure = press ? Math.min(1, p.pressure + dt / PRESS_RAMP) : Math.max(0, p.pressure - dt * PRESS_RELEASE); | |
| 40 | if (p.pressure > HARD_PRESS && p.wobble > CALM) p.phase = 'collapsed'; | |
| 41 | else if (p.pressure >= MIN_PRESS) p.wobble *= Math.exp(-DECAY * p.pressure * dt); | |
| 42 | else p.wobble = Math.min(1, p.wobble + DRIFT * dt); | |
| 43 | if (p.phase === 'centre' && p.wobble <= CENTRED) { p.phase = 'pull'; p.wobble = 0; p.pressure = 0; } | |
| 44 | } else if (p.phase === 'pull') { | |
| 45 | p.rate = pull; | |
| 46 | if (pull < MIN_RATE) p.height = Math.max(0, p.height - SLUMP * dt); | |
| 47 | else { | |
| 48 | const gain = Math.min(MAX_HEIGHT - p.height, pull * PULL_SPEED * dt); | |
| 49 | p.height += gain; | |
| 50 | p.thickness -= gain * (THIN_BASE + THIN_FAST * pull ** 3); | |
| 51 | if (p.thickness < TEAR_THICKNESS) p.phase = 'torn'; | |
| 52 | else if (p.height >= MAX_HEIGHT) p.phase = 'done'; | |
| 53 | } | |
| 54 | } | |
| 55 | if (p.elapsed >= TIME_LIMIT) { | |
| 56 | if (p.phase === 'centre' || (p.phase === 'pull' && p.height < 1)) p.phase = 'dried'; | |
| 57 | else if (p.phase === 'pull') { p.phase = 'done'; p.rate = 0; } | |
| 58 | } | |
| 59 | return p; | |
| 60 | } | |
| 61 | ||
| 62 | // the potter lifts their hands: a pulled pot goes to the kiln as it is | |
| 63 | function finish(pot) { | |
| 64 | return pot.phase === 'pull' ? { ...pot, phase: 'done', rate: 0 } : { ...pot }; | |
| 65 | } | |
| 66 | ||
| 67 | // the height in pixels a pot is worth once the round is over; a ruined pot is worth nothing | |
| 68 | const heightOf = pot => (pot.phase === 'done' ? Math.floor(pot.height) : 0); | |
| 69 | const score = heights => heights.reduce((sum, h) => sum + (Number.isFinite(h) ? Math.max(0, Math.floor(h)) : 0), 0); | |
| 70 | const over = pot => pot.phase === 'done' || pot.phase === 'collapsed' || pot.phase === 'torn' || pot.phase === 'dried'; | |
| 71 | ||
| 72 | const api = { | |
| 73 | POTS, TIME_LIMIT, MAX_HEIGHT, PULL_SPEED, WOBBLE_START, CENTRED, HARD_PRESS, CALM, MIN_PRESS, MIN_RATE, TEAR_THICKNESS, | |
| 74 | newPot, step, finish, heightOf, score, over, | |
| 75 | }; | |
| 76 | if (typeof module !== 'undefined') module.exports = api; else root.Clay = api; | |
| 77 | })(typeof window !== 'undefined' ? window : globalThis); |
pottery-wheel/clay.test.mjs added +117
| @@ -0,0 +1,117 @@ | ||
| 1 | import { test, expect } from 'bun:test'; | |
| 2 | import C from './clay.js'; | |
| 3 | ||
| 4 | const run = (pot, input, seconds, dt = .02) => { | |
| 5 | for (let t = 0; t < seconds && !C.over(pot) && !(pot.phase === 'pull' && input.stopAtPull); t += dt) pot = C.step(pot, input, dt); | |
| 6 | return pot; | |
| 7 | }; | |
| 8 | // presses in pulses, easing off before the pressure gets hard, as a steady potter would | |
| 9 | function centre(pot) { | |
| 10 | for (let t = 0; t < 20 && pot.phase === 'centre'; t += .02) pot = C.step(pot, { press: pot.pressure < .5 || pot.wobble < C.CALM }, .02); | |
| 11 | return pot; | |
| 12 | } | |
| 13 | const centred = () => centre(C.newPot()); | |
| 14 | ||
| 15 | test('steady pressure centres the clay and moves on to pulling', () => { | |
| 16 | const pot = centred(); | |
| 17 | expect(pot.phase).toBe('pull'); | |
| 18 | expect(pot.wobble).toBe(0); | |
| 19 | }); | |
| 20 | ||
| 21 | test('pressure decays the wobble, no pressure lets it drift back', () => { | |
| 22 | const pressed = run(C.newPot(), { press: true }, .5); | |
| 23 | expect(pressed.wobble).toBeLessThan(C.WOBBLE_START); | |
| 24 | const idle = run(C.newPot(.5), { press: false }, 2); | |
| 25 | expect(idle.wobble).toBeGreaterThan(.5); | |
| 26 | }); | |
| 27 | ||
| 28 | test('hard pressure on a wobbling lump collapses it', () => { | |
| 29 | const pot = run(C.newPot(), { press: true }, 5); | |
| 30 | expect(pot.phase).toBe('collapsed'); | |
| 31 | expect(C.heightOf(pot)).toBe(0); | |
| 32 | }); | |
| 33 | ||
| 34 | test('hard pressure on a calm lump is fine', () => { | |
| 35 | let pot = C.newPot(C.CALM - .05); | |
| 36 | pot.pressure = .9; | |
| 37 | pot = C.step(pot, { press: true }, .02); | |
| 38 | expect(pot.phase).not.toBe('collapsed'); | |
| 39 | }); | |
| 40 | ||
| 41 | test('pulling at a steady rate raises the wall and thins it a little', () => { | |
| 42 | const pot = run(centred(), { pull: .4 }, 1); | |
| 43 | expect(pot.phase).toBe('pull'); | |
| 44 | expect(pot.height).toBeCloseTo(24, 0); | |
| 45 | expect(pot.thickness).toBeLessThan(1); | |
| 46 | expect(pot.thickness).toBeGreaterThan(C.TEAR_THICKNESS); | |
| 47 | }); | |
| 48 | ||
| 49 | test('pulling too fast thins the wall until it tears', () => { | |
| 50 | const pot = run(centred(), { pull: .95 }, 3); | |
| 51 | expect(pot.phase).toBe('torn'); | |
| 52 | expect(C.heightOf(pot)).toBe(0); | |
| 53 | }); | |
| 54 | ||
| 55 | test('a faster pull is thinner at the same height than a slower one', () => { | |
| 56 | const fast = run(centred(), { pull: .6 }, .5), slow = run(centred(), { pull: .3 }, 1); | |
| 57 | expect(Math.abs(fast.height - slow.height)).toBeLessThan(2); | |
| 58 | expect(fast.thickness).toBeLessThan(slow.thickness); | |
| 59 | }); | |
| 60 | ||
| 61 | test('pulling too slow lets the wall slump', () => { | |
| 62 | let pot = run(centred(), { pull: .4 }, 1); | |
| 63 | const before = pot.height; | |
| 64 | pot = run(pot, { pull: .1 }, 1); | |
| 65 | expect(pot.height).toBeLessThan(before); | |
| 66 | expect(run(centred(), { pull: .1 }, 2).height).toBe(0); | |
| 67 | }); | |
| 68 | ||
| 69 | test('a gentle pull reaches the full height and fires itself', () => { | |
| 70 | const pot = run(centred(), { pull: .36 }, 10); | |
| 71 | expect(pot.phase).toBe('done'); | |
| 72 | expect(C.heightOf(pot)).toBe(C.MAX_HEIGHT); | |
| 73 | }); | |
| 74 | ||
| 75 | test('finishing early keeps the height, and only a finished pot scores', () => { | |
| 76 | const pulled = run(centred(), { pull: .4 }, 1); | |
| 77 | const done = C.finish(pulled); | |
| 78 | expect(C.heightOf(done)).toBe(Math.floor(pulled.height)); | |
| 79 | expect(C.heightOf(pulled)).toBe(0); | |
| 80 | expect(C.finish(C.newPot()).phase).toBe('centre'); | |
| 81 | }); | |
| 82 | ||
| 83 | test('the round score is the total height, and bad input counts for nothing', () => { | |
| 84 | expect(C.score([40, 30, 20])).toBe(90); | |
| 85 | expect(C.score([40, NaN, -5, 20.9])).toBe(60); | |
| 86 | }); | |
| 87 | ||
| 88 | test('step ignores bad input and never mutates', () => { | |
| 89 | const pot = C.newPot(); | |
| 90 | const same = C.step(pot, { press: true }, NaN); | |
| 91 | expect(same).toEqual(pot); | |
| 92 | C.step(pot, { press: true, pull: 'x' }, .1); | |
| 93 | expect(pot.pressure).toBe(0); | |
| 94 | }); | |
| 95 | ||
| 96 | test('a pot still being centred when the time runs out dries, it is not blamed on pressure', () => { | |
| 97 | let pot = C.newPot(); | |
| 98 | for (let t = 0; t < C.TIME_LIMIT + 1 && !C.over(pot); t += .02) pot = C.step(pot, { press: false }, .02); | |
| 99 | expect(pot.phase).toBe('dried'); | |
| 100 | expect(pot.elapsed).toBeGreaterThanOrEqual(C.TIME_LIMIT); | |
| 101 | expect(C.heightOf(pot)).toBe(0); | |
| 102 | }); | |
| 103 | ||
| 104 | test('a pull that runs out of time is fired as it stands, and a slumped one dries', () => { | |
| 105 | let pot = { ...C.newPot(), phase: 'pull', height: 20, thickness: 1, elapsed: C.TIME_LIMIT - .01 }; | |
| 106 | pot = C.step(pot, { pull: 0 }, .02); | |
| 107 | expect(pot.phase).toBe('done'); | |
| 108 | expect(C.heightOf(pot)).toBe(19); | |
| 109 | const flat = C.step({ ...C.newPot(), phase: 'pull', elapsed: C.TIME_LIMIT - .01 }, { pull: 0 }, .02); | |
| 110 | expect(flat.phase).toBe('dried'); | |
| 111 | }); | |
| 112 | ||
| 113 | test('time only counts while the pot is being worked', () => { | |
| 114 | const pot = C.step(C.newPot(), { press: false }, .5); | |
| 115 | expect(pot.elapsed).toBe(.5); | |
| 116 | expect(C.step(pot, { press: false }, 0).elapsed).toBe(.5); | |
| 117 | }); |
pottery-wheel/index.html added +458
| @@ -0,0 +1,458 @@ | ||
| 1 | ||
| 2 | <html lang="en"> | |
| 3 | <head> | |
| 4 | <meta charset="utf-8"> | |
| 5 | <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"> | |
| 6 | <title>Pottery Wheel</title> | |
| 7 | <style> | |
| 8 | :root { : #1c1b19; : #8b877f; : #fff; : #b4452f; } | |
| 9 | * { box-sizing: border-box; } | |
| 10 | html, body { height: 100%; margin: 0; background: var(); color: var(); } | |
| 11 | body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; } | |
| 12 | #stage { position: fixed; inset: 0; display: grid; place-items: center; } | |
| 13 | canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; } | |
| 14 | .hud { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; gap: 16px; pointer-events: none; } | |
| 15 | #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; } | |
| 16 | #bottom { bottom: max(14px, env(safe-area-inset-bottom)); align-items: flex-end; } | |
| 17 | .row { display: flex; align-items: center; gap: 8px; color: var(); } | |
| 18 | .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; } | |
| 19 | .row span { color: var(); } | |
| 20 | .dots { display: flex; gap: 3px; } | |
| 21 | .dots i { width: 6px; height: 6px; background: var(); } | |
| 22 | .dots i.off { opacity: .16; } | |
| 23 | #status { color: var(); } | |
| 24 | #actions { display: flex; gap: 18px; } | |
| 25 | button { pointer-events: auto; font: inherit; color: var(); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; } | |
| 26 | button:hover, button:focus-visible { color: var(); } | |
| 27 | #fire[hidden] { display: none; } | |
| 28 | </style> | |
| 29 | </head> | |
| 30 | <body> | |
| 31 | <div id="stage"><canvas id="c" tabindex="0" aria-label="Potter's corner with a kick wheel, a stool and a shelf of pots. Hold to press the clay until it is centred, easing off if it wobbles. Then drag up to pull the wall, not too fast and not too slow, and fire the pot. Keyboard: hold space to press, hold the up arrow to pull, F to fire. Each pot has 40 seconds; clay still being centred when they run out dries and is lost."></canvas></div> | |
| 32 | <div id="scores"> | |
| 33 | <div class="row"><b id="total">0</b><span>px total</span><span class="dots" id="pots"></span></div> | |
| 34 | <div class="row"><b id="best">0</b><span>best</span></div> | |
| 35 | <div class="row"><b id="time">40</b><span>s left on this pot</span></div> | |
| 36 | </div> | |
| 37 | <div class="hud" id="bottom"> | |
| 38 | <div id="status" role="status" aria-live="polite"></div> | |
| 39 | <div id="actions"><button id="fire" type="button" hidden>fire the pot</button><button id="mute" type="button" aria-pressed="false">sound on</button></div> | |
| 40 | </div> | |
| 41 | <script src="../shell.js"></script> | |
| 42 | <script> | |
| 43 | PixelPlays.mount({ | |
| 44 | id: 'pottery-wheel', | |
| 45 | rules: [ | |
| 46 | 'Hold to press the clay centred. Press hard while it wobbles and it collapses.', | |
| 47 | 'Then drag up (or press up) to pull the wall: too fast tears it, too slow slumps. Fire the pot early with the "fire the pot" button or F; each pot gets 40 seconds, and clay still being centred when they run out dries and is lost.', | |
| 48 | ], | |
| 49 | }); | |
| 50 | </script> | |
| 51 | <script>window.PP_SCENE = { originY: 40, shadowX: 1.3, shadowY: -.12 };</script> | |
| 52 | <script src="../engine.js"></script> | |
| 53 | <script src="clay.js"></script> | |
| 54 | <script> | |
| 55 | 'use strict'; | |
| 56 | ||
| 57 | const CLAY = window.Clay; | |
| 58 | const HEAD_Z = 1.15, HEAD_R = 2.6, SHELF_X = -8, SHELF_Z = 2.8, SLOTS = [0, 3.2, 6.4]; | |
| 59 | const LUMP = 14, R0 = 19, SHELF_SCALE = .5; | |
| 60 | const KIND_TILE = 6; | |
| 61 | const TILE_A = [206, 190, 170], TILE_B = [190, 172, 152], WOOD = [150, 100, 70], IRON = [84, 88, 98], STOOL = [176, 128, 82]; | |
| 62 | const WET = [150, 132, 122], SKIN = [222, 170, 132]; | |
| 63 | const GLAZES = [[196, 98, 64], [70, 130, 140], [214, 168, 70]]; | |
| 64 | const FIRE = rgb(255, 150, 48); | |
| 65 | const wetRamp = rampOf(WET), skinRamp = rampOf(SKIN), glazeRamps = GLAZES.map(rampOf); | |
| 66 | const stems = []; | |
| 67 | ||
| 68 | function groundColor(x, y, ix, iy, i) { | |
| 69 | const edge = Math.hypot(x, y) / 14; | |
| 70 | const rough = edge + (noise(x * 1.3, y * 1.3) - .5) * .13; | |
| 71 | if (rough > 1.04) return 0; | |
| 72 | if (rough > .93 && hash(ix, iy) < (rough - .93) / .11) return 0; | |
| 73 | const fine = hash(ix, iy); | |
| 74 | if (rough > .82 + (noise(x * .5, y * .5) - .5) * .1) { | |
| 75 | kinds[i] = KIND_GRASS; | |
| 76 | const t = noise(x * .9, y * .9) * 1.15 + (fine - .5) * .55 - .08; | |
| 77 | return rgb(...GRASS[clamp(Math.floor(t * 4.2), 0, 3)]); | |
| 78 | } | |
| 79 | kinds[i] = KIND_TILE; | |
| 80 | const tile = (Math.floor(x / 1.6) + Math.floor(y / 1.6)) & 1 ? TILE_A : TILE_B; | |
| 81 | return rampOf(tile)[clamp(Math.floor(2.4 + (noise(x * 2, y * 2) - .5) * 1.6 + (bayerAt(ix, iy) - .5) * .5), 1, 3)]; | |
| 82 | } | |
| 83 | // a flat disc of the given colour at height z, with a little thickness under it | |
| 84 | function disc(r, z0, z1, c) { | |
| 85 | const ramp = rampOf(c); | |
| 86 | for (let z = z0; z <= z1 + .001; z += .04) { | |
| 87 | const top = z >= z1 - .001; | |
| 88 | for (let x = -r; x <= r; x += .045) for (let y = -r; y <= r; y += .045) { | |
| 89 | const d = Math.hypot(x, y); | |
| 90 | if (d > r) continue; | |
| 91 | const shade = top ? 3.3 - d / r * .5 + (noise(x * 6, y * 6) - .5) * .5 : 1.6 + (x - y) * .25 / r; | |
| 92 | const p = project(x, y, z), ix = p.sx | 0, iy = p.sy | 0; | |
| 93 | if (ix < 0 || iy < 0 || ix >= W || iy >= H) continue; | |
| 94 | const i = iy * W + ix; | |
| 95 | if (p.d <= zb[i]) continue; | |
| 96 | zb[i] = p.d; | |
| 97 | pix[i] = ramp[clamp(Math.floor(shade + (bayerAt(ix, iy) - .5) * .5), 0, 4)]; | |
| 98 | } | |
| 99 | } | |
| 100 | } | |
| 101 | function bake() { | |
| 102 | zb.fill(-1e9); | |
| 103 | pix.fill(rgb(255, 255, 255)); | |
| 104 | for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) { | |
| 105 | const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy, i); | |
| 106 | if (!c) continue; | |
| 107 | pix[i] = c; ground[i] = 1; | |
| 108 | zb[i] = (g.x + g.y) / R2 * COS; | |
| 109 | } | |
| 110 | growGrass(); | |
| 111 | groundZ.set(zb); | |
| 112 | ||
| 113 | // the kick wheel: a heavy flywheel low down, a shaft, and the head the clay sits on | |
| 114 | disc(3.4, .12, .3, IRON); | |
| 115 | box(-.3, -.3, .3, .3, .3, HEAD_Z - .2, IRON, 3); | |
| 116 | disc(HEAD_R, HEAD_Z - .2, HEAD_Z, [120, 120, 130]); | |
| 117 | // the stool in front of the wheel | |
| 118 | box(3.0, 3.0, 1.7, 4.4, 4.4, 1.9, STOOL, 5); | |
| 119 | for (const [x, y] of [[3.1, 3.1], [4.1, 3.1], [3.1, 4.1], [4.1, 4.1]]) box(x, y, 0, x + .2, y + .2, 1.7, WOOD, 7); | |
| 120 | // the shelf of finished pots, with a post at each end and in the middle | |
| 121 | box(SHELF_X - .8, -2, SHELF_Z - .2, SHELF_X + .8, 9.4, SHELF_Z, WOOD, 9); | |
| 122 | box(SHELF_X - .8, -2, 1.1, SHELF_X + .8, 9.4, 1.3, WOOD, 15); | |
| 123 | for (const y of [-1.8, 3.6, 9.2]) box(SHELF_X - .7, y, 0, SHELF_X - .45, y + .25, SHELF_Z - .2, WOOD, 11); | |
| 124 | // a potted plant at the far end of the shelf; its stems are drawn dynamically so they can sway | |
| 125 | box(SHELF_X - .35, 8.3, SHELF_Z, SHELF_X + .35, 9.0, SHELF_Z + .7, [176, 98, 70], 13); | |
| 126 | for (let k = 0; k < 7; k++) { | |
| 127 | const p = project(SHELF_X, 8.65, SHELF_Z + .7); | |
| 128 | stems.push({ x: p.sx | 0, y: p.sy | 0, lean: (k - 3) * .9, len: 9 + (k * 5) % 6, k }); | |
| 129 | } | |
| 130 | castShadow(3.7, 3.7, 1.9, .9); | |
| 131 | ||
| 132 | bakeOcclusion(); | |
| 133 | staticShadow.set(shadowMask); | |
| 134 | applyShadows(groundZ); | |
| 135 | bakedPix.set(pix); | |
| 136 | bakedZ.set(zb); | |
| 137 | } | |
| 138 | ||
| 139 | /* ---------- game state ---------- */ | |
| 140 | const BEST_KEY = 'pottery-wheel-best'; | |
| 141 | function loadBest() { try { return Math.max(0, parseInt(localStorage.getItem(BEST_KEY), 10) || 0); } catch (e) { return 0; } } | |
| 142 | function saveBest(v) { try { localStorage.setItem(BEST_KEY, String(v)); } catch (e) { /* private mode: the best lives for the session */ } } | |
| 143 | const PULL_PER_PX = 1 / CLAY.PULL_SPEED; // a finger moving as fast as the wall rises is a rate of 1 | |
| 144 | const G = { | |
| 145 | phase: 'play', pot: CLAY.newPot(), potsLeft: CLAY.POTS, shelf: [], timer: 0, time: 0, angle: 0, | |
| 146 | press: false, keyPress: false, keyUp: false, keyRate: 0, touchRate: 0, dragY: null, dragT: 0, | |
| 147 | best: loadBest(), status: '', turn: 0, glaze: 0, shownTime: -1, | |
| 148 | }; | |
| 149 | const nodes = { | |
| 150 | total: document.getElementById('total'), best: document.getElementById('best'), pots: document.getElementById('pots'), | |
| 151 | time: document.getElementById('time'), status: document.getElementById('status'), fire: document.getElementById('fire'), | |
| 152 | }; | |
| 153 | const total = () => CLAY.score(G.shelf.map(p => p.h)); | |
| 154 | function renderTime() { | |
| 155 | const s = Math.max(0, Math.ceil(CLAY.TIME_LIMIT - G.pot.elapsed)); | |
| 156 | if (s !== G.shownTime) { G.shownTime = s; nodes.time.textContent = s; } | |
| 157 | } | |
| 158 | function renderHud() { | |
| 159 | nodes.total.textContent = total(); | |
| 160 | nodes.best.textContent = G.best; | |
| 161 | renderTime(); | |
| 162 | if (nodes.pots.children.length !== CLAY.POTS) nodes.pots.innerHTML = '<i></i>'.repeat(CLAY.POTS); | |
| 163 | [...nodes.pots.children].forEach((el, k) => el.classList.toggle('off', k >= G.potsLeft)); | |
| 164 | nodes.fire.hidden = !(G.phase === 'play' && G.pot.phase === 'pull'); | |
| 165 | } | |
| 166 | function setStatus(text) { | |
| 167 | if (text === G.status) return; | |
| 168 | G.status = text; | |
| 169 | nodes.status.textContent = text; | |
| 170 | } | |
| 171 | function nextPot() { | |
| 172 | G.phase = 'play'; G.timer = 0; G.turn = G.shelf.length; | |
| 173 | G.pot = CLAY.newPot(CLAY.WOBBLE_START - (G.turn % 2) * .05); | |
| 174 | G.keyRate = 0; G.touchRate = 0; | |
| 175 | setStatus('hold to press the clay, ease off if it wobbles'); | |
| 176 | renderHud(); | |
| 177 | } | |
| 178 | function newRound() { | |
| 179 | G.shelf = []; G.potsLeft = CLAY.POTS; | |
| 180 | nextPot(); | |
| 181 | } | |
| 182 | function fireNow() { | |
| 183 | if (G.phase !== 'play' || G.pot.phase !== 'pull') return; | |
| 184 | G.pot = CLAY.finish(G.pot); | |
| 185 | endPot(); | |
| 186 | } | |
| 187 | // the pot is done one way or another: ruined ones crumple, finished ones go to the kiln | |
| 188 | function endPot() { | |
outdated
A timed-out pot also lands here with the 'pressed too hard while it wobbled' message. It needs its own reason. |
||
| 189 | G.phase = G.pot.phase === 'done' ? 'fire' : 'ruin'; G.timer = 0; G.press = G.keyPress = false; | |
| 190 | G.potsLeft--; | |
| 191 | const h = CLAY.heightOf(G.pot); | |
| 192 | G.glaze = G.turn % GLAZES.length; | |
| 193 | G.shelf.push({ h, glaze: G.glaze, drawH: LUMP + Math.floor(G.pot.height), wall: G.pot.thickness }); | |
| 194 | const why = { collapsed: 'it collapsed, pressed too hard while it wobbled', torn: 'the wall tore, pulled too fast', dried: 'the clay dried out, out of time' }[G.pot.phase]; | |
| 195 | setStatus(why ? `${why} · 0 px` : `${h} px, into the kiln`); | |
| 196 | sound(why ? 'drop' : 'fire'); | |
| 197 | renderHud(); | |
| 198 | } | |
| 199 | function afterPot() { | |
| 200 | if (G.potsLeft) return nextPot(); | |
| 201 | G.phase = 'end'; G.timer = 0; | |
| 202 | const sum = total(), record = sum > G.best; | |
| 203 | if (record) { G.best = sum; saveBest(sum); sound('point'); } | |
| 204 | setStatus(`${sum} px in total${record ? ', a new best' : ''} · best ${G.best} · tap for a new round`); | |
| 205 | renderHud(); | |
| 206 | } | |
| 207 | ||
| 208 | /* ---------- input ---------- */ | |
| 209 | function pressDown() { | |
| 210 | ensureAudio(); | |
| 211 | if (G.phase === 'end' && G.timer > .8) return newRound(); | |
| 212 | if (G.phase === 'play' && G.pot.phase === 'centre') G.press = true; | |
| 213 | } | |
| 214 | function pressUp() { G.press = false; } | |
| 215 | canvas.addEventListener('pointerdown', e => { | |
| 216 | canvas.focus({ preventScroll: true }); | |
| 217 | canvas.setPointerCapture(e.pointerId); | |
| 218 | G.dragY = e.clientY; G.dragT = performance.now(); | |
| 219 | pressDown(); | |
| 220 | }); | |
| 221 | canvas.addEventListener('pointermove', e => { | |
| 222 | if (G.dragY === null) return; | |
| 223 | const now = performance.now(), dt = Math.max(8, now - G.dragT) / 1000; | |
| 224 | const scale = canvas.getBoundingClientRect().height / H; | |
| 225 | const rate = Math.max(0, (G.dragY - e.clientY) / scale / dt) * PULL_PER_PX; // finger px per second against wall px per second | |
| 226 | if (G.phase === 'play' && G.pot.phase === 'pull') G.touchRate = Math.min(1, G.touchRate + (rate - G.touchRate) * .4); | |
| 227 | G.dragY = e.clientY; G.dragT = now; | |
| 228 | }); | |
| 229 | function pointerEnd() { G.dragY = null; pressUp(); } | |
| 230 | canvas.addEventListener('pointerup', pointerEnd); | |
| 231 | canvas.addEventListener('pointercancel', pointerEnd); | |
| 232 | canvas.addEventListener('keydown', e => { | |
| 233 | if (e.key === 'ArrowUp') { e.preventDefault(); G.keyUp = true; return; } | |
| 234 | if (e.key === 'f' || e.key === 'F' || (e.key === 'Enter' && G.pot.phase === 'pull')) { e.preventDefault(); return fireNow(); } | |
| 235 | if (e.key !== ' ' && e.key !== 'Enter') return; | |
| 236 | e.preventDefault(); | |
| 237 | if (!e.repeat) { G.keyPress = true; pressDown(); } | |
| 238 | }); | |
| 239 | canvas.addEventListener('keyup', e => { | |
| 240 | if (e.key === 'ArrowUp') G.keyUp = false; | |
| 241 | if (e.key === ' ' || e.key === 'Enter') { G.keyPress = false; pressUp(); } | |
| 242 | }); | |
| 243 | canvas.addEventListener('blur', () => { G.keyUp = G.keyPress = false; pointerEnd(); }); | |
| 244 | nodes.fire.addEventListener('click', () => { fireNow(); canvas.focus({ preventScroll: true }); }); | |
| 245 | ||
| 246 | /* ---------- update ---------- */ | |
| 247 | const KEY_START = .25, KEY_CLIMB = .12, KEY_FALL = 2, TOUCH_FALL = 8; | |
| 248 | function update(dt) { | |
| 249 | G.time += dt; | |
| 250 | const pot = G.pot; | |
| 251 | const wheelSpeed = G.phase === 'play' || G.phase === 'fire' ? 5.5 : G.phase === 'ruin' ? 2 : 0; | |
| 252 | G.angle += wheelSpeed * dt; | |
| 253 | if (G.phase === 'play') { | |
outdated
This 40 s limit isn't shown anywhere, isn't in |
||
| 254 | // the up arrow starts gently and climbs the longer it is held; letting go drops it fast | |
| 255 | G.keyRate = G.keyUp ? Math.min(1, Math.max(G.keyRate, KEY_START) + KEY_CLIMB * dt) : Math.max(0, G.keyRate - KEY_FALL * dt); | |
| 256 | G.touchRate *= Math.exp(-TOUCH_FALL * dt); | |
| 257 | const was = pot.phase; | |
| 258 | G.pot = CLAY.step(pot, { press: G.press || G.keyPress, pull: Math.max(G.keyRate, G.touchRate) }, dt); | |
| 259 | if (was === 'centre' && G.pot.phase === 'pull') { setStatus('centred · drag up or hold the up arrow to pull'); sound('point'); renderHud(); } | |
| 260 | if (CLAY.over(G.pot)) return endPot(); | |
| 261 | renderTime(); | |
| 262 | hint(); | |
| 263 | } else if (G.phase === 'fire') { G.timer += dt; if (G.timer > 2.2) afterPot(); } | |
| 264 | else if (G.phase === 'ruin') { G.timer += dt; if (G.timer > 1.6) afterPot(); } | |
| 265 | else if (G.phase === 'end') G.timer += dt; | |
| 266 | } | |
| 267 | function hint() { | |
| 268 | const p = G.pot; | |
| 269 | if (p.phase === 'centre') { | |
| 270 | if (p.pressure > .5 && p.wobble > CLAY.CALM) setStatus('easing off keeps it from collapsing'); | |
| 271 | else if (G.status.startsWith('easing')) setStatus('hold to press the clay, ease off if it wobbles'); | |
| 272 | } else if (p.phase === 'pull' && p.height > 0 || p.rate > 0) { | |
| 273 | if (p.rate > .6) setStatus('too fast, the wall is thinning'); | |
| 274 | else if (p.rate > 0 && p.rate < CLAY.MIN_RATE) setStatus('too slow, it slumps'); | |
| 275 | else if (p.rate >= CLAY.MIN_RATE) setStatus(`${Math.floor(p.height)} px · wall ${Math.round(p.thickness * 100)}%`); | |
| 276 | } | |
| 277 | } | |
| 278 | ||
| 279 | /* ---------- drawing ---------- */ | |
| 280 | const put = (ix, iy, c) => { if (ix >= 0 && iy >= 0 && ix < W && iy < H) pix[iy * W + ix] = c; }; | |
| 281 | // the profile of a pot: radius in pixels at level k of a pot drawn n pixels tall | |
| 282 | function radiusAt(k, n, pulled, squash) { | |
| 283 | const frac = n > 0 ? k / n : 0; | |
| 284 | const base = lerp(R0 + 3, R0 - 4, clamp(pulled / CLAY.MAX_HEIGHT, 0, 1)) * (1 + squash * .12); | |
| 285 | const belly = 1 + .22 * Math.sin(Math.PI * Math.min(1, frac * 1.05)) * clamp(pulled / 24, 0, 1); | |
| 286 | const dome = lerp(Math.sqrt(Math.max(0, 1 - Math.pow(Math.max(0, frac - .55) / .45, 2) * .75)), 1, clamp(pulled / LUMP, 0, 1)); | |
| 287 | return base * belly * dome; | |
| 288 | } | |
| 289 | // Draws the spinning clay as stacked flat ellipses, one per pixel of height, in whole-pixel bands. | |
| 290 | // o: { cx, base, n (drawn height), pulled, wobble, angle, scale, wall, ramp, glow, notch, squash, flat } | |
| 291 | function drawClay(o) { | |
| 292 | const scale = o.scale || 1, ramp = o.ramp, n = Math.max(2, Math.round(o.n)); | |
| 293 | for (let k = 0; k <= n; k++) { | |
| 294 | const r = Math.max(2, Math.round(radiusAt(k, n, o.pulled, o.squash || 0) * scale * (o.flat || 1))); | |
| 295 | const off = Math.round(o.wobble * 10 * scale * Math.sin(o.angle + k * .07)); | |
| 296 | const cy = Math.round(o.base - k), cx = Math.round(o.cx) + off, ry = Math.max(1, Math.round(r * .5)); | |
| 297 | const top = k === n; | |
| 298 | const inner = top && o.pulled > 2 ? Math.max(1, r - Math.max(2, Math.round((2 + o.wall * 4) * scale))) : 0; | |
| 299 | for (let dy = -ry; dy <= ry; dy++) { | |
| 300 | const half = Math.floor(r * Math.sqrt(1 - (dy * dy) / (ry * ry)) + .5); | |
| 301 | for (let dx = -half; dx <= half; dx++) { | |
| 302 | if (o.notch && k > n - 9 && dx > 3 && dx < 13 && dy > -ry * .6) continue; | |
| 303 | const u = clamp(dx / r, -1, 1); | |
| 304 | let shade = u < -.5 ? 4 : u < .05 ? 3 : u < .55 ? 2 : 1; | |
| 305 | // marks that turn with the clay: whole-pixel bands, one step darker | |
| 306 | if ((Math.floor((Math.asin(u) + o.angle) * 2.4) & 3) === 0) shade--; | |
| 307 | if (top) { | |
| 308 | const ex = dx / Math.max(1, inner), ey = dy / Math.max(1, Math.round(inner * .5)); | |
| 309 | if (inner && ex * ex + ey * ey < 1) shade = dy < 0 ? 1 : 0; // inside the pot: the far wall catches light, the near one is in shade | |
| 310 | else shade = Math.min(4, 3 + (dx < 0 ? 1 : 0)); | |
| 311 | } | |
| 312 | let c = ramp[clamp(shade, 0, 4)]; | |
| 313 | if (o.glow > 0 && bayerAt(cx + dx, cy + dy) < o.glow) c = FIRE; | |
| 314 | put(cx + dx, cy + dy, c); | |
| 315 | } | |
| 316 | } | |
| 317 | } | |
| 318 | } | |
| 319 | function drawHands(cx, y, gap, press) { | |
| 320 | for (const side of [-1, 1]) { | |
| 321 | const x0 = Math.round(cx + side * (gap + (press ? 0 : 2))) - (side < 0 ? 8 : 0); | |
| 322 | for (let dy = 0; dy < 11; dy++) for (let dx = 0; dx < 8; dx++) { | |
| 323 | const edge = (side < 0 ? dx === 0 : dx === 7) || dy === 10; | |
| 324 | put(x0 + dx, Math.round(y) - 8 + dy, edge ? skinRamp[0] : skinRamp[dy < 4 ? 4 : 3]); | |
| 325 | } | |
| 326 | } | |
| 327 | } | |
| 328 | function wheelMarks() { | |
| 329 | // four marks on the head and four on the flywheel turn with the wheel | |
| 330 | for (let k = 0; k < 4; k++) { | |
| 331 | const a = G.angle + k * Math.PI / 2; | |
| 332 | for (const [r, z, c] of [[HEAD_R - .35, HEAD_Z + .01, rgb(70, 70, 82)], [3.1, .31, rgb(150, 154, 166)]]) { | |
| 333 | const x = Math.cos(a) * r, y = Math.sin(a) * r; | |
| 334 | const p = project(x, y, z), ix = p.sx | 0, iy = p.sy | 0; | |
| 335 | if (Math.sin(a) + Math.cos(a) < -.2 && r < 3) continue; | |
| 336 | put(ix, iy, c); put(ix + 1, iy, c); | |
| 337 | } | |
| 338 | } | |
| 339 | } | |
| 340 | function plant() { | |
| 341 | const t = STILL ? 0 : Math.floor(G.time * WIND_FPS) / WIND_FPS; | |
| 342 | const leaf = rgb(...GRASS[3]), deep = rgb(...GRASS[1]); | |
| 343 | for (const s of stems) { | |
| 344 | const sway = Math.round(Math.sin(t * .9 + s.k) * 1.2); | |
| 345 | for (let j = 1; j <= s.len; j++) { | |
| 346 | const bend = s.lean * j / s.len, x = Math.round(s.x + bend * 3 * (j / s.len) + sway * j / s.len); | |
| 347 | put(x, s.y - j, j > s.len - 3 ? leaf : deep); | |
| 348 | if (j > s.len - 4) put(x + (s.lean < 0 ? -1 : 1), s.y - j, leaf); | |
| 349 | } | |
| 350 | } | |
| 351 | } | |
| 352 | // where a slot on the shelf lands on the canvas | |
| 353 | function slotAt(i) { const p = project(SHELF_X, SLOTS[i], SHELF_Z); return { x: p.sx, y: p.sy }; } | |
| 354 | ||
| 355 | function potOnShelf(s, i) { | |
| 356 | const at = slotAt(i); | |
| 357 | drawClay({ cx: at.x, base: at.y, n: s.drawH, pulled: s.drawH - LUMP, wobble: 0, angle: 0, scale: SHELF_SCALE, wall: s.wall, ramp: glazeRamps[s.glaze], flat: 1 }); | |
| 358 | // a glaze band about a third of the way up | |
| 359 | const band = Math.round(s.drawH * .38); | |
| 360 | for (let dx = -8; dx <= 8; dx++) for (let dy = 0; dy < 2; dy++) { | |
| 361 | const w = Math.round(radiusAt(band, s.drawH, s.drawH - LUMP, 0) * SHELF_SCALE); | |
| 362 | if (Math.abs(dx) <= w) put(Math.round(at.x) + dx, Math.round(at.y - band) + dy, glazeRamps[(s.glaze + 1) % 3][dx < 0 ? 4 : 3]); | |
| 363 | } | |
| 364 | } | |
| 365 | function draw() { | |
| 366 | pix.set(bakedPix); | |
| 367 | zb.set(bakedZ); | |
| 368 | const head = project(0, 0, HEAD_Z), cx = head.sx, base = head.sy; | |
| 369 | const p = G.pot, shown = G.phase === 'play' || G.phase === 'fire' || G.phase === 'ruin'; | |
| 370 | // what the clay on the wheel looks like right now | |
| 371 | let o = null; | |
| 372 | if (shown) { | |
| 373 | const pulled = G.phase === 'play' || G.phase === 'ruin' && p.phase === 'torn' ? p.height : G.shelf[G.shelf.length - 1].drawH - LUMP; | |
| 374 | const squash = G.phase === 'play' ? p.pressure : 0; | |
| 375 | o = { cx, base, n: LUMP * (1 - squash * .22) + pulled, pulled, wobble: p.wobble, angle: G.angle, wall: p.thickness, ramp: wetRamp, squash }; | |
| 376 | if (G.phase === 'play' && p.phase === 'centre') o.pulled = 0; | |
| 377 | if (G.phase === 'ruin') { | |
| 378 | const t = clamp(G.timer / 1.2, 0, 1); | |
| 379 | if (p.phase === 'collapsed' || p.phase === 'dried') { o.n = LUMP * (1 - ease(t) * .7); o.flat = 1 + ease(t) * .5; o.wobble = p.wobble * (1 - t * .5); } | |
| 380 | else { o.n = (LUMP + pulled) * (1 - ease(t) * .8); o.flat = 1 + ease(t) * .4; o.notch = t < .5; } | |
| 381 | } else if (G.phase === 'fire') { | |
| 382 | const t = clamp(G.timer / 1.6, 0, 1); | |
| 383 | o.ramp = t < .5 ? wetRamp : glazeRamps[G.glaze]; | |
| 384 | o.glow = t < 1 ? Math.sin(Math.PI * t) * .9 : 0; | |
| 385 | } | |
| 386 | // the hard shadow falls screen-right, one slice per few pixels of height | |
| 387 | for (let k = 0; k <= o.n; k += 4) castShadow(0, 0, HEAD_Z + k / (S * COS), radiusAt(k, o.n, o.pulled, o.squash) / S * (o.flat || 1), 1, 0); | |
| 388 | } | |
| 389 | applyShadows(bakedZ); | |
| 390 | shadeEdges(); | |
| 391 | wheelMarks(); | |
| 392 | plant(); | |
| 393 | G.shelf.forEach((s, i) => { | |
| 394 | if (G.phase === 'fire' && i === G.shelf.length - 1) return; | |
| 395 | if (s.h > 0) potOnShelf(s, i); | |
| 396 | }); | |
| 397 | if (G.phase === 'fire' && G.timer > 1.6) { | |
| 398 | // the fired pot rides up to its place on the shelf | |
| 399 | const t = ease(clamp((G.timer - 1.6) / .6, 0, 1)), i = G.shelf.length - 1, at = slotAt(i), s = G.shelf[i]; | |
| 400 | const lift = Math.sin(Math.PI * t) * 24; | |
| 401 | drawClay({ cx: lerp(cx, at.x, t), base: lerp(base, at.y, t) - lift, n: s.drawH, pulled: s.drawH - LUMP, wobble: 0, angle: G.angle, scale: lerp(1, SHELF_SCALE, t), wall: s.wall, ramp: glazeRamps[s.glaze] }); | |
| 402 | } else if (o) { | |
| 403 | drawClay(o); | |
| 404 | if (G.phase === 'play') { | |
| 405 | const reach = p.phase === 'centre' ? 8 + (1 - p.pressure) * 4 : 6 + Math.max(0, p.rate) * 2; | |
| 406 | const side = radiusAt(Math.min(o.n, p.phase === 'centre' ? 8 : o.n - 6), o.n, o.pulled, o.squash); | |
| 407 | drawHands(cx, base - (p.phase === 'centre' ? 8 : Math.max(8, o.n - 6)), side - 3 + reach * .4, p.phase === 'centre' ? p.pressure > .15 : true); | |
| 408 | } | |
| 409 | } | |
| 410 | ctx.putImageData(image, 0, 0); | |
| 411 | } | |
| 412 | ||
| 413 | /* ---------- sound ---------- */ | |
| 414 | let audio = null, muted = false; | |
| 415 | function ensureAudio() { | |
| 416 | if (audio) { if (audio.state === 'suspended') audio.resume(); return; } | |
| 417 | const AC = window.AudioContext || window.webkitAudioContext; | |
| 418 | if (AC) audio = new AC(); | |
| 419 | } | |
| 420 | function sound(kind) { | |
| 421 | if (!audio || muted) return; | |
| 422 | const now = audio.currentTime, gain = audio.createGain(), osc = audio.createOscillator(); | |
| 423 | const spec = { | |
| 424 | fire: [260, 520, .4, .08, 'triangle'], | |
| 425 | drop: [180, 60, .2, .16, 'sine'], | |
| 426 | point: [660, 880, .16, .08, 'triangle'], | |
| 427 | }[kind]; | |
| 428 | osc.type = spec[4]; | |
| 429 | osc.frequency.setValueAtTime(spec[0], now); | |
| 430 | osc.frequency.exponentialRampToValueAtTime(spec[1], now + spec[2]); | |
| 431 | gain.gain.setValueAtTime(spec[3], now); | |
| 432 | gain.gain.exponentialRampToValueAtTime(.0005, now + spec[2]); | |
| 433 | osc.connect(gain).connect(audio.destination); | |
| 434 | osc.start(now); osc.stop(now + spec[2] + .01); | |
| 435 | } | |
| 436 | const muteButton = document.getElementById('mute'); | |
| 437 | muteButton.addEventListener('click', () => { | |
| 438 | muted = !muted; | |
| 439 | muteButton.textContent = muted ? 'sound off' : 'sound on'; | |
| 440 | muteButton.setAttribute('aria-pressed', String(muted)); | |
| 441 | }); | |
| 442 | ||
| 443 | /* ---------- fit and boot ---------- */ | |
| 444 | addEventListener('resize', fit); | |
| 445 | fit(); | |
| 446 | bake(); | |
| 447 | nextPot(); | |
| 448 | let last = performance.now(); | |
| 449 | function frame(now) { | |
| 450 | update(Math.min(.04, (now - last) / 1000)); | |
| 451 | last = now; | |
| 452 | draw(); | |
| 453 | requestAnimationFrame(frame); | |
| 454 | } | |
| 455 | requestAnimationFrame(frame); | |
| 456 | </script> | |
| 457 | </body> | |
| 458 | </html> |
serve.test.mjs +7
| @@ -87,6 +87,13 @@ test('pizza toss is served without a track', async () => { | ||
| 87 | 87 | expect((await fetch(base + '/pizza-toss/toss.js')).status).toBe(200); |
| 88 | 88 | }); |
| 89 | 89 | |
| 90 | test('pottery wheel is served without a track', async () => { | |
| 91 | const page = await fetch(base + '/pottery-wheel/'); | |
| 92 | expect(page.status).toBe(200); | |
| 93 | expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8'); | |
| 94 | expect((await fetch(base + '/pottery-wheel/clay.js')).status).toBe(200); | |
| 95 | }); | |
| 96 | ||
| 90 | 97 | test('a game folder without its slash redirects to it', async () => { |
| 91 | 98 | const res = await fetch(base + '/balote', { redirect: 'manual' }); |
| 92 | 99 | expect(res.status).toBe(308); |
shell.js +1
| @@ -14,6 +14,7 @@ window.PixelPlays = (() => { | ||
| 14 | 14 | { id: 'pizza-toss', title: 'Pizza Toss', blurb: 'Five tosses of pizza dough: hold to spin, catch it before it drops, too much spin tears it', music: false, forged: true }, |
| 15 | 15 | { id: 'harbour-crane', title: 'Harbour Crane', blurb: 'Stack ten crates onto a bobbing fishing boat from a swinging crane hook', music: false, forged: true }, |
| 16 | 16 | { id: 'sled-run', title: 'Sled Run', blurb: 'Ride a sledge down a snowy hill: tuck for speed, release on a kicker to jump, land flat', music: false, forged: true }, |
| 17 | { id: 'pottery-wheel', title: 'Pottery Wheel', blurb: 'Shape a pot on a kick wheel: hold to centre the clay without collapsing it, then pull the wall as tall as you can before it tears', music: false, forged: true }, | |
| 17 | 18 | { id: 'row-home', title: 'Row Home', blurb: 'Race a rowing boat across the river against a bot: stroke in rhythm with the glide, too early catches a crab', music: false, forged: true }, |
| 18 | 19 | ]; |
| 19 | 20 | const MUSIC_VOLUME = .4; |
new above
offline
Say how to fire early here (the 'fire the pot' button, or F), as the README does.