@capyclaw/offline-ddr0 0.0.0-stage → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +441 -2
- package/client/client.js +603 -0
- package/cordis.patch.yml +13 -0
- package/docs/STORAGE-MIGRATION.md +136 -0
- package/lib/atomic.mjs +40 -0
- package/lib/http-cache.mjs +42 -0
- package/lib/inbox.mjs +64 -0
- package/lib/media.mjs +242 -0
- package/lib/migrate-json.mjs +101 -0
- package/lib/mirror-index.mjs +105 -0
- package/lib/mirror.mjs +123 -0
- package/lib/proxy.mjs +188 -0
- package/lib/remote.mjs +158 -0
- package/lib/render.mjs +93 -0
- package/lib/repository.mjs +71 -0
- package/lib/store.mjs +610 -0
- package/lib/surface.mjs +74 -0
- package/lib/sync-ui.mjs +108 -0
- package/lib/sync.mjs +433 -0
- package/lib/wire.mjs +211 -0
- package/lib/workstore-repository.mjs +316 -0
- package/lib/workstore.mjs +348 -0
- package/mirror/files/00001.html +2045 -0
- package/mirror/files/00002.json +1 -0
- package/mirror/files/00003.json +1 -0
- package/mirror/files/00004.json +1 -0
- package/mirror/files/00005.json +1 -0
- package/mirror/files/00006.json +1 -0
- package/mirror/files/00007.json +1 -0
- package/mirror/files/00008.json +1 -0
- package/mirror/files/00009.json +1 -0
- package/mirror/files/00010.json +1 -0
- package/mirror/files/00011.json +1 -0
- package/mirror/files/00012.json +1 -0
- package/mirror/files/00013.json +1 -0
- package/mirror/files/00014.json +1 -0
- package/mirror/files/00015.json +1 -0
- package/mirror/files/00016.json +1 -0
- package/mirror/files/00017.json +1 -0
- package/mirror/files/00018.json +1 -0
- package/mirror/files/00019.json +1 -0
- package/mirror/files/00020.json +1 -0
- package/mirror/files/00021.json +1 -0
- package/mirror/files/00022.json +1 -0
- package/mirror/files/00023.js +205 -0
- package/mirror/files/00024.json +1 -0
- package/mirror/files/00025.json +1 -0
- package/mirror/files/00026.json +1 -0
- package/mirror/files/00027.js +51 -0
- package/mirror/files/00028.json +1 -0
- package/mirror/files/00029.json +1 -0
- package/mirror/files/00030.json +1 -0
- package/mirror/files/00031.json +1 -0
- package/mirror/files/00032.json +1 -0
- package/mirror/files/00033.json +1 -0
- package/mirror/files/00034.json +1 -0
- package/mirror/files/00035.json +1 -0
- package/mirror/files/00036.json +1 -0
- package/mirror/files/00037.json +1 -0
- package/mirror/files/00038.json +1 -0
- package/mirror/files/00039.json +1 -0
- package/mirror/files/00040.js +2311 -0
- package/mirror/files/00041.json +1 -0
- package/mirror/files/00042.json +1 -0
- package/mirror/files/00043.json +1 -0
- package/mirror/files/00044.json +1 -0
- package/mirror/files/00045.js +575 -0
- package/mirror/files/00046.json +1 -0
- package/mirror/files/00047.js +575 -0
- package/mirror/files/00048.js +575 -0
- package/mirror/files/00049.json +1 -0
- package/mirror/files/00050.json +1 -0
- package/mirror/files/00051.json +1 -0
- package/mirror/files/00052.json +1 -0
- package/mirror/files/00053.js +575 -0
- package/mirror/files/00054.json +1 -0
- package/mirror/files/00055.json +1 -0
- package/mirror/files/00056.js +575 -0
- package/mirror/files/00057.json +1 -0
- package/mirror/files/00058.json +1 -0
- package/mirror/files/00059.js +360 -0
- package/mirror/files/00060.json +1 -0
- package/mirror/files/00061.json +1 -0
- package/mirror/files/00062.json +1 -0
- package/mirror/files/00063.json +1 -0
- package/mirror/files/00064.json +1 -0
- package/mirror/files/00065.js +144 -0
- package/mirror/files/00066.js +7 -0
- package/mirror/files/00067.json +1 -0
- package/mirror/files/00068.json +1 -0
- package/mirror/files/00069.json +1 -0
- package/mirror/files/00070.json +1 -0
- package/mirror/files/00071.json +1 -0
- package/mirror/files/00072.json +1 -0
- package/mirror/files/00073.js +1 -0
- package/mirror/files/00074.json +1 -0
- package/mirror/files/00075.json +1 -0
- package/mirror/files/00076.json +1 -0
- package/mirror/files/00077.js +45 -0
- package/mirror/files/00078.js +1348 -0
- package/mirror/files/00079.json +1 -0
- package/mirror/files/00080.json +1 -0
- package/mirror/files/00081.js +1 -0
- package/mirror/files/00082.json +1 -0
- package/mirror/files/00083.json +1 -0
- package/mirror/files/00084.js +7 -0
- package/mirror/files/00085.json +1 -0
- package/mirror/files/00086.json +1 -0
- package/mirror/files/00087.js +7 -0
- package/mirror/files/00088.json +1 -0
- package/mirror/files/00089.json +1 -0
- package/mirror/files/00090.js +7 -0
- package/mirror/files/00091.json +1 -0
- package/mirror/files/00092.json +1 -0
- package/mirror/files/00093.js +102 -0
- package/mirror/files/00094.json +1 -0
- package/mirror/files/00095.json +1 -0
- package/mirror/files/00096.json +1 -0
- package/mirror/files/00097.json +1 -0
- package/mirror/files/00098.json +1 -0
- package/mirror/files/00099.json +1 -0
- package/mirror/files/00100.json +1 -0
- package/mirror/files/00101.js +102 -0
- package/mirror/files/00102.json +1 -0
- package/mirror/files/00103.json +1 -0
- package/mirror/files/00104.json +1 -0
- package/mirror/files/00105.json +1 -0
- package/mirror/files/00106.json +1 -0
- package/mirror/files/00107.js +110 -0
- package/mirror/files/00108.json +1 -0
- package/mirror/files/00109.json +1 -0
- package/mirror/files/00110.json +1 -0
- package/mirror/files/00111.json +1 -0
- package/mirror/files/00112.json +1 -0
- package/mirror/files/00113.json +1 -0
- package/mirror/files/00114.json +1 -0
- package/mirror/files/00115.json +1 -0
- package/mirror/files/00116.json +1 -0
- package/mirror/files/00117.json +1 -0
- package/mirror/files/00118.json +1 -0
- package/mirror/files/00119.json +1 -0
- package/mirror/files/00120.json +1 -0
- package/mirror/files/00121.json +1 -0
- package/mirror/files/00122.json +1 -0
- package/mirror/files/00123.json +1 -0
- package/mirror/files/00124.json +1 -0
- package/mirror/files/00125.json +1 -0
- package/mirror/files/00126.json +1 -0
- package/mirror/files/00127.json +1 -0
- package/mirror/files/00128.json +1 -0
- package/mirror/files/00129.json +1 -0
- package/mirror/files/00130.json +1 -0
- package/mirror/files/00131.json +1 -0
- package/mirror/files/00132.js +110 -0
- package/mirror/files/00133.json +1 -0
- package/mirror/files/00134.json +1 -0
- package/mirror/files/00135.json +1 -0
- package/mirror/files/00136.json +1 -0
- package/mirror/files/00137.js +26 -0
- package/mirror/files/00138.json +1 -0
- package/mirror/files/00139.json +1 -0
- package/mirror/files/00140.json +1 -0
- package/mirror/files/00141.json +1 -0
- package/mirror/files/00142.json +1 -0
- package/mirror/files/00143.json +1 -0
- package/mirror/files/00144.js +26 -0
- package/mirror/files/00145.json +1 -0
- package/mirror/files/00146.json +1 -0
- package/mirror/files/00147.js +29 -0
- package/mirror/files/00148.json +1 -0
- package/mirror/files/00149.json +1 -0
- package/mirror/files/00150.js +23 -0
- package/mirror/files/00151.json +1 -0
- package/mirror/files/00152.json +1 -0
- package/mirror/files/00153.js +719 -0
- package/mirror/files/00154.js +9575 -0
- package/mirror/files/00155.js +108 -0
- package/mirror/files/00156.js +379 -0
- package/mirror/files/00157.js +48 -0
- package/mirror/files/00158.json +16 -0
- package/mirror/manifest.json +1582 -0
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +310 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +88 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +50 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +72 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +38 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +88 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +54 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +195 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +198 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +71 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +664 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +570 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +289 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +58 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +230 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
- package/node_modules/@capyclaw/work-store/README.md +83 -0
- package/node_modules/@capyclaw/work-store/STANDARD.md +263 -0
- package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
- package/node_modules/@capyclaw/work-store/dsh-suite.json +33 -0
- package/node_modules/@capyclaw/work-store/icon.svg +7 -0
- package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
- package/node_modules/@capyclaw/work-store/package.json +68 -0
- package/node_modules/@capyclaw/work-store/src/backend.mjs +90 -0
- package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
- package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
- package/node_modules/@capyclaw/work-store/src/index.mjs +571 -0
- package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
- package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
- package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
- package/package.json +82 -4
- package/plugin.mjs +644 -0
- package/static/index.html +2068 -0
|
@@ -0,0 +1,1348 @@
|
|
|
1
|
+
/* Prickle Patch — 落日刺猬快打(whac.html 平台移植版)
|
|
2
|
+
* WorkView 沙箱:作品界面 = 舞台内容本身,全 absolute 单层容器;
|
|
3
|
+
* 存档走平台桥 localStorage 假面(镜像作品数据区),代码零改动。 */
|
|
4
|
+
let __ppTeardown = null;
|
|
5
|
+
Work.register({
|
|
6
|
+
mount(__wv) {
|
|
7
|
+
const stage = __wv.stage;
|
|
8
|
+
if (__wv.hold) __wv.hold();
|
|
9
|
+
let __ppDead = false;
|
|
10
|
+
const __ppRaf = new Set(), __ppEls = [];
|
|
11
|
+
const __hadRaf = Object.prototype.hasOwnProperty.call(window, 'requestAnimationFrame');
|
|
12
|
+
const __hadWae = Object.prototype.hasOwnProperty.call(window, 'addEventListener');
|
|
13
|
+
const __hadDae = Object.prototype.hasOwnProperty.call(document, 'addEventListener');
|
|
14
|
+
const _raf = window.requestAnimationFrame.bind(window);
|
|
15
|
+
const _wae = window.addEventListener.bind(window);
|
|
16
|
+
const _dae = document.addEventListener.bind(document);
|
|
17
|
+
window.requestAnimationFrame = cb => {
|
|
18
|
+
const id = _raf(t => { __ppRaf.delete(id); if (!__ppDead) cb(t); });
|
|
19
|
+
__ppRaf.add(id); return id;
|
|
20
|
+
};
|
|
21
|
+
window.addEventListener = (t, fn, o) => { __ppEls.push([window, t, fn, o]); _wae(t, fn, o); };
|
|
22
|
+
document.addEventListener = (t, fn, o) => { __ppEls.push([document, t, fn, o]); _dae(t, fn, o); };
|
|
23
|
+
|
|
24
|
+
const style = document.createElement('style');
|
|
25
|
+
style.textContent = "\n:root{--paper:#f3e9d3;--ink:#1d1813;--rust:#c9412d;--mari:#e07a3a;--sky:150px;--sab:env(safe-area-inset-bottom,0px);--sat:env(safe-area-inset-top,0px)}\n*{box-sizing:border-box;margin:0;padding:0}\nhtml,body{height:100%;background:#24402a;overflow:hidden;overscroll-behavior:none}\nbody{font-family:Fraunces,Georgia,serif;color:var(--ink);-webkit-user-select:none;user-select:none;touch-action:none;-webkit-tap-highlight-color:transparent;\n font-variation-settings:'SOFT' 50,'opsz' 72;font-variant-numeric:lining-nums tabular-nums}\n#cv{position:absolute;inset:0;width:100%;height:100%;display:block;opacity:0;transition:opacity .5s ease-out}\nbody.ready #cv{opacity:1}\nbutton{font:inherit;color:inherit;cursor:pointer}\nbutton:focus-visible{outline:3px solid var(--ink);outline-offset:3px}\n/* a garden tag: cut card with a notched end, printed in ink */\n.tag{position:relative;background:var(--paper);border:3px solid var(--ink);border-radius:4px 9px 9px 4px;\n clip-path:polygon(0 50%,14px 0,100% 0,100% 100%,14px 100%);padding:4px 14px 4px 22px;box-shadow:3px 3px 0 rgba(29,24,19,.35)}\n#hud{position:absolute;inset:0;pointer-events:none;transition:opacity .4s ease-out}\n.tags{position:absolute;left:max(calc(10px + env(safe-area-inset-left,0px)),var(--side,0px));right:max(calc(10px + env(safe-area-inset-right,0px)),var(--side,0px));bottom:calc(14px + var(--sab));display:flex;gap:8px;align-items:center;justify-content:space-between}\n#scoreTag{transform:rotate(-1.5deg);min-width:96px}\n#score{display:block;font-size:clamp(26px,3.6vw,40px);font-weight:900;line-height:1.05;font-variation-settings:'SOFT' 50,'WONK' 1,'opsz' 72}\n#streakTag{display:flex;align-items:center;gap:8px;transform:rotate(1.5deg);transition:transform .2s cubic-bezier(.3,1.6,.5,1)}\n#mult{font-size:clamp(22px,3vw,32px);font-weight:900;line-height:1.05;min-width:1.6em;font-variation-settings:'SOFT' 50,'WONK' 1,'opsz' 72}\n#pips{display:flex;gap:3px}\n#pips i{display:block;width:clamp(28px,2.6vw,32px);height:clamp(28px,2.6vw,32px);transition:transform .18s cubic-bezier(.3,1.8,.5,1)}\n#pips svg{display:block;width:100%;height:100%}\n#pips .petals{fill:var(--paper);transition:fill .12s}#pips .heart{fill:var(--paper);transition:fill .12s}\n#pips i.on{transform:scale(1.12) rotate(18deg)}#pips i.hop{animation:hop .32s cubic-bezier(.3,1.8,.5,1)}\n@keyframes hop{0%{transform:scale(.6) rotate(-40deg)}60%{transform:scale(1.45) rotate(30deg)}100%{transform:scale(1.12) rotate(18deg)}}#pips i.on .petals{fill:var(--mari)}#pips i.on .heart{fill:#8a3a22}\n#streakTag.bump{animation:bump .45s cubic-bezier(.3,1.6,.5,1)}\n#streakTag.lose #pips{animation:lose .4s ease-out}#streakTag.lose #pips i{animation:wilt .4s ease-out}\n@keyframes wilt{0%{transform:scale(1.12) rotate(18deg)}40%{transform:scale(.7) rotate(-30deg)}100%{transform:none}}\n#streakTag.max{background:#f6cf6a}\n@keyframes bump{0%{transform:rotate(1.5deg) scale(1)}30%{transform:rotate(-3deg) scale(1.18)}100%{transform:rotate(1.5deg) scale(1)}}\n@keyframes lose{0%{transform:translateX(0)}25%{transform:translateX(-5px)}50%{transform:translateX(4px)}75%{transform:translateX(-2px)}100%{transform:none}}\n#mute{position:absolute;right:calc(10px + env(safe-area-inset-right,0px));top:calc(10px + var(--sat));pointer-events:auto;width:46px;height:46px;border-radius:6px 6px 23px 23px;\n border:3px solid var(--ink);background:var(--paper);display:grid;place-items:center;transform:rotate(3deg);box-shadow:3px 3px 0 rgba(29,24,19,.35)}\n#mute svg{width:22px;height:22px;margin-top:4px}#mute .x{display:none}#mute.off .w{display:none}#mute.off .x{display:block}\n#mute:before{content:'';position:absolute;top:4px;left:50%;margin-left:-3px;width:4px;height:4px;border-radius:50%;border:2px solid var(--ink)}\nbody[data-mode=title] .tags,body[data-mode=results] .tags{opacity:0}\n.tags{transition:opacity .3s}\n/* the tags sit at our feet, under the burrows, so the sky stays clear for the sun */\n/* title */\n#title{position:absolute;left:0;right:0;top:calc(var(--sky) + 6px);display:flex;flex-direction:column;align-items:center;gap:10px;pointer-events:none;\n animation:in .6s cubic-bezier(.2,1.4,.4,1) both}\n#title .big{transform:rotate(-2deg);padding:8px 30px 10px 40px;clip-path:polygon(0 50%,22px 0,100% 0,100% 100%,22px 100%);border-width:4px;box-shadow:5px 5px 0 rgba(29,24,19,.35)}\n#title h1{font-size:clamp(38px,8vw,72px);font-weight:900;line-height:.95;letter-spacing:-.01em;font-variation-settings:'SOFT' 100,'WONK' 1,'opsz' 144}\n#title h1 em{font-style:italic;color:var(--rust)}\n#title .sub{font-size:clamp(14px,2.2vw,18px);font-weight:600;font-style:italic;margin-top:2px;text-align:center}\n#titleBest{transform:rotate(1.5deg);font-size:16px;font-weight:700}\n#titleBest b{font-weight:900}\n@keyframes in{from{opacity:0;transform:translateY(-14px)}to{opacity:1;transform:none}}\n/* results: a seed-packet card that slides up out of the night */\n#results{position:absolute;left:50%;top:50%;width:min(380px,calc(100vw - 32px));transform:translate(-50%,-50%) rotate(-6deg) scale(1.25);opacity:0;pointer-events:none;\n transition:transform .42s cubic-bezier(.2,1.5,.4,1),opacity .08s linear;background:var(--paper);border:4px solid var(--ink);border-radius:10px;\n box-shadow:6px 6px 0 rgba(0,0,0,.45);padding:18px 22px 16px;text-align:center}\n#results.show{opacity:1;transform:translate(-50%,-50%) rotate(-1deg) scale(1);pointer-events:auto}\n#results .hd{font-size:15px;font-weight:700;letter-spacing:.18em;text-transform:uppercase;font-variant-caps:all-small-caps;font-size:19px}\n#resScore{display:block;font-size:clamp(52px,14vw,72px);font-weight:900;line-height:1;margin:2px 0 4px;font-variation-settings:'SOFT' 100,'WONK' 1,'opsz' 144}\n#resStamp{position:absolute;right:14px;top:16px;transform:rotate(12deg);border:3px solid var(--rust);color:var(--rust);border-radius:6px;padding:2px 8px;font-weight:900;font-size:15px;\n letter-spacing:.06em;text-transform:uppercase;animation:stamp .4s .5s cubic-bezier(.3,1.8,.5,1) both}\n@keyframes stamp{from{opacity:0;transform:rotate(12deg) scale(2)}to{opacity:1;transform:rotate(12deg) scale(1)}}\n#resRank{font-size:22px;font-weight:900;font-style:italic;color:var(--rust)}\n#resNext,#resBest{font-size:14px;font-weight:600;min-height:1.2em}\n.stats{display:flex;justify-content:center;gap:18px;margin:12px 0 14px;padding:10px 0;border-top:2px dashed rgba(29,24,19,.5);border-bottom:2px dashed rgba(29,24,19,.5)}\n.stats div{display:flex;flex-direction:column;align-items:center;font-size:12px;font-weight:700;letter-spacing:.08em;text-transform:uppercase}\n.stats b{font-size:24px;font-weight:900;letter-spacing:0}\n#again{border:3px solid var(--ink);background:var(--mari);border-radius:6px 12px 12px 6px;padding:10px 34px 12px 40px;font-size:24px;font-weight:900;\n clip-path:polygon(0 50%,18px 0,100% 0,100% 100%,18px 100%);box-shadow:3px 3px 0 rgba(29,24,19,.4);transition:transform .12s}\n#again:active{transform:scale(.96)}\n.foot{margin-top:10px;font-size:12px;font-weight:600;opacity:.75}.foot a{color:inherit}\n#pause{position:absolute;inset:0;display:grid;place-items:center;background:rgba(13,15,25,.45)}\n#pause .tag{font-size:24px;font-weight:900;padding:10px 26px 12px 34px;transform:rotate(-2deg)}\n#pause .tag small{display:block;font-size:14px;font-weight:600;font-style:italic}\n[hidden]{display:none!important}\n@media (prefers-reduced-motion:reduce){*{animation-duration:.01s!important;transition-duration:.01s!important}}\n";
|
|
26
|
+
document.head.appendChild(style);
|
|
27
|
+
stage.innerHTML = "\n<canvas id=\"cv\" aria-label=\"A garden with nine burrows. Hedgehogs come up out of them; boop each one on the nose. Leave the wasps alone.\"></canvas>\n<div id=\"hud\">\n <div class=\"tags\">\n <div class=\"tag\" id=\"scoreTag\"><span id=\"score\">0</span></div>\n <div class=\"tag\" id=\"streakTag\"><span id=\"mult\">×1</span><span id=\"pips\"></span></div>\n </div>\n <button id=\"mute\" aria-label=\"Sound off\"><svg viewBox=\"0 0 20 20\" aria-hidden=\"true\"><path d=\"M3 7.5h3l4-3.5v12l-4-3.5H3z\" fill=\"#1d1813\"/><path class=\"w\" d=\"M13 7a4 4 0 0 1 0 6M15 5a7 7 0 0 1 0 10\" stroke=\"#1d1813\" stroke-width=\"2.2\" fill=\"none\" stroke-linecap=\"round\"/><path class=\"x\" d=\"M13 7.5l5 5M18 7.5l-5 5\" stroke=\"#1d1813\" stroke-width=\"2.2\" stroke-linecap=\"round\"/></svg></button>\n</div>\n<div id=\"title\">\n <div class=\"tag big\"><h1>Prickle <em>Patch</em></h1><div class=\"sub\">a sunset of hedgehogs</div></div>\n <div class=\"tag\" id=\"titleBest\" hidden>Best <b id=\"titleBestN\">0</b> · <span id=\"titleRank\"></span></div>\n</div>\n<div id=\"results\" role=\"dialog\" aria-labelledby=\"resHd\">\n <div class=\"hd\" id=\"resHd\">Nightfall</div>\n <span id=\"resScore\">0</span>\n <span id=\"resStamp\" hidden>New best</span>\n <div id=\"resRank\"></div>\n <div id=\"resNext\"></div>\n <div class=\"stats\"><div><b id=\"resBoops\">0</b>boops</div><div><b id=\"resStreak\">0</b>best streak</div><div><b id=\"resStings\">0</b>stings</div></div>\n <div id=\"resBest\"></div>\n <button id=\"again\">Again</button>\n \n</div>\n<div id=\"pause\" hidden><div class=\"tag\">Paused<small>tap to carry on</small></div></div>\n";
|
|
28
|
+
|
|
29
|
+
/* ---- 游戏本体(whac.html 原样移植) ---- */
|
|
30
|
+
|
|
31
|
+
// Prickle Patch - the rules. No DOM, no clock of its own: the page calls step(dt) and tap(hole).
|
|
32
|
+
// One round is one evening: ROUND seconds of sun. Hedgehogs come up out of nine burrows; boop them
|
|
33
|
+
// before they tuck in and drop away. Wasps come up too; touching one is a sting, and costs sun.
|
|
34
|
+
const PrickleCore = (() => {
|
|
35
|
+
const ROUND = 45; // seconds of evening
|
|
36
|
+
const STING_COST = 4; // a sting burns this much sun
|
|
37
|
+
const APPLE_GIFT = 2; // an apple gives this much back
|
|
38
|
+
const PIPS = 5, MAX_MULT = 5;
|
|
39
|
+
const RISE = 0.14, TUCK = 0.16, SINK = 0.2, DROP = 0.26, FLEE = 0.42, GRACE = 0.1;
|
|
40
|
+
const RANKS = [[0, 'Seedling'], [3000, 'Weeder'], [8000, 'Gardener'], [16000, 'Head Gardener'], [28000, 'Hedgehog Whisperer']];
|
|
41
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
42
|
+
const clamp = (v, a, b) => v < a ? a : v > b ? b : v;
|
|
43
|
+
|
|
44
|
+
function rng(seed) {
|
|
45
|
+
let a = seed >>> 0 || 1;
|
|
46
|
+
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; };
|
|
47
|
+
}
|
|
48
|
+
// how far into the evening: the sun's own position, so a sting brings night on faster and an
|
|
49
|
+
// apple holds it back
|
|
50
|
+
const dusk = s => clamp(1 - s.left / ROUND, 0, 1);
|
|
51
|
+
|
|
52
|
+
function create(opt = {}) {
|
|
53
|
+
return {
|
|
54
|
+
seed: opt.seed >>> 0 || 1, rand: rng(opt.seed || 1), tutorial: !!opt.tutorial,
|
|
55
|
+
t: 0, left: ROUND, over: false,
|
|
56
|
+
score: 0, streak: 0, bestStreak: 0, mult: 1, pips: 0,
|
|
57
|
+
boops: 0, misses: 0, stings: 0, apples: 0, spawned: 0, wasps: 0,
|
|
58
|
+
holes: new Array(9).fill(null), nextId: 1,
|
|
59
|
+
nextSpawn: opt.tutorial ? 0.05 : 0.3, lastApple: 0, recent: [], firstWasp: false
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ---- the tempo of the evening, d = 0 at golden hour, 1 at dark
|
|
64
|
+
const tempo = {
|
|
65
|
+
warn: d => lerp(0.3, 0.17, d), // how long a burrow heaves before something comes up
|
|
66
|
+
hogUp: d => lerp(1.25, 0.62, d), // how long a hedgehog waits to be booped
|
|
67
|
+
waspUp: d => lerp(1.7, 1.1, d), // how long a wasp hangs about
|
|
68
|
+
gap: d => lerp(0.95, 0.4, Math.pow(d, 0.9)), // time between arrivals
|
|
69
|
+
cap: d => Math.min(4, 2 + Math.floor(d * 2.5)), // most burrows busy at once
|
|
70
|
+
wasp: d => lerp(0.15, 0.3, d) // chance an arrival is a wasp
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function busy(s) { return s.holes.filter(Boolean).length; }
|
|
74
|
+
function pickHole(s) {
|
|
75
|
+
const free = [];
|
|
76
|
+
for (let i = 0; i < 9; i++) if (!s.holes[i]) free.push(i);
|
|
77
|
+
if (!free.length) return -1;
|
|
78
|
+
const fresh = free.filter(i => !s.recent.includes(i));
|
|
79
|
+
const from = fresh.length ? fresh : free;
|
|
80
|
+
return from[Math.floor(s.rand() * from.length)];
|
|
81
|
+
}
|
|
82
|
+
function spawn(s, ev) {
|
|
83
|
+
const d = dusk(s), tut = s.tutorial && s.t < 12;
|
|
84
|
+
const cap = tut ? 1 : tempo.cap(d);
|
|
85
|
+
if (busy(s) >= cap) { s.nextSpawn = s.t + 0.12; return; }
|
|
86
|
+
let kind = 'hog';
|
|
87
|
+
if (tut) {
|
|
88
|
+
// the first round teaches one thing at a time: three hedgehogs, then a wasp, alone
|
|
89
|
+
if (s.spawned >= 3 && !s.firstWasp) kind = 'wasp';
|
|
90
|
+
} else if (s.t > 6 && s.rand() < tempo.wasp(d) && !(d < 0.4 && s.holes.some(e => e && e.kind === 'wasp'))) kind = 'wasp';
|
|
91
|
+
if (!s.tutorial && s.t > 6 && !s.firstWasp) kind = 'wasp';
|
|
92
|
+
const hole = pickHole(s); if (hole < 0) { s.nextSpawn = s.t + 0.12; return; }
|
|
93
|
+
const apple = kind === 'hog' && s.t > 10 && s.t - s.lastApple > 11 + s.rand() * 4;
|
|
94
|
+
if (apple) s.lastApple = s.t;
|
|
95
|
+
if (kind === 'wasp') { s.firstWasp = true; s.wasps++; }
|
|
96
|
+
const warn = tempo.warn(d), up = kind === 'wasp' ? tempo.waspUp(d) : tut ? 1.7 : tempo.hogUp(d);
|
|
97
|
+
const e = {id: s.nextId++, kind, apple, hole, phase: 'warn', t0: s.t, warn, up, upAt: 0};
|
|
98
|
+
s.holes[hole] = e; s.spawned++;
|
|
99
|
+
s.recent.push(hole); if (s.recent.length > 2) s.recent.shift();
|
|
100
|
+
ev.push({type: 'warn', hole, kind, apple, id: e.id});
|
|
101
|
+
s.nextSpawn = s.t + (tut ? 1.15 : tempo.gap(d) * (0.8 + s.rand() * 0.4));
|
|
102
|
+
}
|
|
103
|
+
function breakStreak(s, hard) {
|
|
104
|
+
s.streak = 0; s.pips = 0;
|
|
105
|
+
s.mult = hard ? 1 : Math.max(1, s.mult - 1);
|
|
106
|
+
}
|
|
107
|
+
// advance the evening by dt seconds; returns what happened, for the page to draw and play
|
|
108
|
+
function step(s, dt) {
|
|
109
|
+
const ev = [];
|
|
110
|
+
if (s.over) { advance(s, dt, ev); return ev; }
|
|
111
|
+
s.t += dt; s.left -= dt;
|
|
112
|
+
if (s.left <= 0) {
|
|
113
|
+
s.left = 0; s.over = true;
|
|
114
|
+
for (const e of s.holes) if (e && e.phase !== 'sink' && e.phase !== 'drop' && e.phase !== 'flee') { e.phase = 'sink'; e.t0 = s.t; }
|
|
115
|
+
ev.push({type: 'end'});
|
|
116
|
+
return ev;
|
|
117
|
+
}
|
|
118
|
+
if (s.t >= s.nextSpawn) spawn(s, ev);
|
|
119
|
+
advance(s, 0, ev);
|
|
120
|
+
return ev;
|
|
121
|
+
}
|
|
122
|
+
function advance(s, dt, ev) {
|
|
123
|
+
if (s.over) s.t += dt;
|
|
124
|
+
for (let i = 0; i < 9; i++) {
|
|
125
|
+
const e = s.holes[i]; if (!e) continue;
|
|
126
|
+
const age = s.t - e.t0;
|
|
127
|
+
if (e.phase === 'warn' && age >= e.warn) { e.phase = 'rise'; e.t0 += e.warn; ev.push({type: 'rise', hole: i, kind: e.kind, apple: e.apple}); }
|
|
128
|
+
else if (e.phase === 'rise' && age >= RISE) { e.phase = 'up'; e.t0 += RISE; e.upAt = e.t0; }
|
|
129
|
+
else if (e.phase === 'up' && age >= e.up) {
|
|
130
|
+
e.phase = e.kind === 'hog' ? 'tuck' : 'sink'; e.t0 += e.up; e.tucked = e.kind === 'hog';
|
|
131
|
+
if (e.kind === 'hog') { s.misses++; breakStreak(s, false); ev.push({type: 'escape', hole: i, apple: e.apple}); }
|
|
132
|
+
else ev.push({type: 'leave', hole: i});
|
|
133
|
+
}
|
|
134
|
+
else if (e.phase === 'tuck' && age >= TUCK) { e.phase = 'sink'; e.t0 += TUCK; }
|
|
135
|
+
else if ((e.phase === 'sink' && age >= SINK) || (e.phase === 'drop' && age >= DROP) || (e.phase === 'flee' && age >= FLEE)) s.holes[i] = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// a touch on burrow i. Returns the events it caused.
|
|
139
|
+
function tap(s, i) {
|
|
140
|
+
const ev = [];
|
|
141
|
+
if (s.over || i < 0 || i > 8) return ev;
|
|
142
|
+
const e = s.holes[i];
|
|
143
|
+
if (!e || e.phase === 'warn' || e.phase === 'sink' || e.phase === 'drop' || e.phase === 'flee' || (e.phase === 'tuck' && s.t - e.t0 > GRACE)) {
|
|
144
|
+
// thumping bare earth: nothing is hurt, but the hedgehogs hear it - the pips empty
|
|
145
|
+
const had = s.pips; if (s.mult < MAX_MULT) s.pips = 0;
|
|
146
|
+
ev.push({type: 'dud', hole: i, lost: had - s.pips}); return ev;
|
|
147
|
+
}
|
|
148
|
+
if (e.kind === 'wasp') {
|
|
149
|
+
s.stings++; s.left = Math.max(0, s.left - STING_COST); breakStreak(s, true);
|
|
150
|
+
e.phase = 'flee'; e.t0 = s.t;
|
|
151
|
+
ev.push({type: 'sting', hole: i, cost: STING_COST});
|
|
152
|
+
return ev;
|
|
153
|
+
}
|
|
154
|
+
if (e.phase === 'tuck') { s.misses--; } // booped in the very last moment: the miss is taken back
|
|
155
|
+
// a quick boop is worth more: full bonus inside a quarter second of the face appearing
|
|
156
|
+
const react = e.phase === 'rise' ? 0 : s.t - e.upAt;
|
|
157
|
+
const quick = Math.round(50 * clamp(1 - (react - 0.25) / 0.5, 0, 1));
|
|
158
|
+
const base = e.apple ? 250 : 100, pts = base * s.mult + quick;
|
|
159
|
+
s.score += pts; s.boops++; s.streak++; s.bestStreak = Math.max(s.bestStreak, s.streak);
|
|
160
|
+
let up = false;
|
|
161
|
+
if (s.mult < MAX_MULT) { s.pips++; if (s.pips >= PIPS) { s.pips = 0; s.mult++; up = true; } } else s.pips = PIPS;
|
|
162
|
+
e.phase = 'drop'; e.t0 = s.t;
|
|
163
|
+
ev.push({type: 'boop', hole: i, pts, quick, apple: e.apple, mult: s.mult, streak: s.streak});
|
|
164
|
+
if (up) ev.push({type: 'mult', mult: s.mult});
|
|
165
|
+
if (e.apple) { s.apples++; const before = s.left; s.left = Math.min(ROUND, s.left + APPLE_GIFT); ev.push({type: 'apple', hole: i, gift: s.left - before}); }
|
|
166
|
+
return ev;
|
|
167
|
+
}
|
|
168
|
+
function rank(score) { let r = RANKS[0]; for (const k of RANKS) if (score >= k[0]) r = k; return r[1]; }
|
|
169
|
+
function nextRank(score) { for (const k of RANKS) if (score < k[0]) return k; return null; }
|
|
170
|
+
return {ROUND, STING_COST, APPLE_GIFT, PIPS, MAX_MULT, RISE, TUCK, SINK, DROP, FLEE, GRACE, RANKS, tempo, dusk, create, step, tap, rank, nextRank, rng};
|
|
171
|
+
})();
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
// Prickle Patch - the print. Everything is drawn as a garden linocut: a few inks on paper, a key
|
|
175
|
+
// block whose lines swell and thin like carved lines do, and gouges cut out of the ink.
|
|
176
|
+
// Sprites are printed once per size and per ink run (dusk, night) and then only placed.
|
|
177
|
+
const Art = (() => {
|
|
178
|
+
const TAU = Math.PI * 2;
|
|
179
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
180
|
+
const clamp = (v, a, b) => v < a ? a : v > b ? b : v;
|
|
181
|
+
const hexc = {};
|
|
182
|
+
const hex = h => hexc[h] || (hexc[h] = (n => [n >> 16 & 255, n >> 8 & 255, n & 255])(parseInt(h.slice(1), 16)));
|
|
183
|
+
const mix = (a, b, t) => { const A = hex(a), B = hex(b); t = clamp(t, 0, 1); return '#' + A.map((v, i) => Math.round(lerp(v, B[i], t)).toString(16).padStart(2, '0')).join(''); };
|
|
184
|
+
const rgba = (h, a) => { const [r, g, b] = hex(h); return `rgba(${r},${g},${b},${a})`; };
|
|
185
|
+
const hash = n => { n = Math.floor(n * 1000) | 0; n = (n ^ 61) ^ (n >>> 16); n = n + (n << 3); n = n ^ (n >>> 4); n = Math.imul(n, 0x27d4eb2d); return ((n ^ (n >>> 15)) >>> 0) / 4294967296; };
|
|
186
|
+
|
|
187
|
+
// Two print runs. Dusk: paper, key, ochre, rust, umber, green, leaf, slate (the shade).
|
|
188
|
+
// Night: the same block re-inked as a white-line print - dark ground, cream lines.
|
|
189
|
+
const INKS = {
|
|
190
|
+
dusk: {
|
|
191
|
+
paper: '#f3e9d3', line: '#1d1813', ink: '#1d1813', bands: ['#b9493a', '#d8683f', '#eb9a48', '#f4c46a'],
|
|
192
|
+
skyHi: '#c9583a', skyLo: '#eba64a', ray: '#f2c46c', sun: '#f6ecd6',
|
|
193
|
+
hedge: '#335535', hedgeLo: '#24402a', nick: '#86a85a',
|
|
194
|
+
lawn: '#5b8644', tick: '#86ab5c', shade: '#34406a',
|
|
195
|
+
soil: '#b4623a', soilCut: '#e9a75a', clod: '#7a4026', soilDeep: '#5e2f1d',
|
|
196
|
+
spine: '#57352a', quill: '#f3e9d3', lit: '#eba64a',
|
|
197
|
+
face: '#f4e3be', faceCut: '#d2a56c', blush: '#d9643f',
|
|
198
|
+
wasp: '#f0b032', waspInk: '#1d1813', wing: '#f3e9d3', waspEye: '#c9412d', apple: '#c9412d', leaf: '#86a85a',
|
|
199
|
+
bed: '#4a2c20', poppy: '#c9412d', mari: '#e07a3a', daisy: '#f3e9d3',
|
|
200
|
+
},
|
|
201
|
+
night: {
|
|
202
|
+
paper: '#efe4cf', line: '#e9dfc8', ink: '#0d0f19', bands: ['#0f1433', '#171f4a', '#212c62', '#2e3b78'],
|
|
203
|
+
skyHi: '#151a3f', skyLo: '#232c63', ray: '#2f3b7c', sun: '#f3e9d3',
|
|
204
|
+
hedge: '#123327', hedgeLo: '#0b231b', nick: '#3f7a5c',
|
|
205
|
+
lawn: '#1b5143', tick: '#2a6e5a', shade: '#0e1a2a',
|
|
206
|
+
soil: '#33384f', soilCut: '#7f89b3', clod: '#262a3d', soilDeep: '#1a1d2b',
|
|
207
|
+
spine: '#2a2236', quill: '#efe4cf', lit: '#f2c96e',
|
|
208
|
+
face: '#dcc394', faceCut: '#a88a66', blush: '#c2584a',
|
|
209
|
+
wasp: '#f2b440', waspInk: '#0d0f19', wing: '#cfd9f0', waspEye: '#e0533a', apple: '#d8462f', leaf: '#3f6a52',
|
|
210
|
+
bed: '#3a2232', poppy: '#c2484a', mari: '#d9a24a', daisy: '#d8d8ea',
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// ---------------------------------------------------------------- shapes as point lists
|
|
215
|
+
function ellipsePts(cx, cy, rx, ry, n, seed = 0, amp = 0, a0 = 0, a1 = TAU) {
|
|
216
|
+
const pts = [], closed = a1 - a0 >= TAU - 1e-6, m = closed ? n : n + 1;
|
|
217
|
+
for (let k = 0; k < m; k++) {
|
|
218
|
+
const a = a0 + (a1 - a0) * k / n, w = 1 + (hash(seed + k * 7.31) - 0.5) * amp * 2;
|
|
219
|
+
pts.push([cx + Math.cos(a) * rx * w, cy + Math.sin(a) * ry * w]);
|
|
220
|
+
}
|
|
221
|
+
return pts;
|
|
222
|
+
}
|
|
223
|
+
function spikePts(cx, cy, rx, ry, n, inner, outer, seed = 0, a0 = 0, a1 = TAU, jit = 0.12) {
|
|
224
|
+
const pts = [], closed = a1 - a0 >= TAU - 1e-6, m = closed ? n * 2 : n * 2 + 1;
|
|
225
|
+
for (let k = 0; k < m; k++) {
|
|
226
|
+
const a = a0 + (a1 - a0) * k / (n * 2), j = 1 + (hash(seed + k * 3.7) - 0.5) * jit;
|
|
227
|
+
const rr = (k % 2 ? outer : inner) * j;
|
|
228
|
+
pts.push([cx + Math.cos(a) * rx * rr, cy + Math.sin(a) * ry * rr]);
|
|
229
|
+
}
|
|
230
|
+
return pts;
|
|
231
|
+
}
|
|
232
|
+
function bez(pts, p0, p1, p2, p3, n = 10) { for (let i = 1; i <= n; i++) { const t = i / n, u = 1 - t; pts.push([u * u * u * p0[0] + 3 * u * u * t * p1[0] + 3 * u * t * t * p2[0] + t * t * t * p3[0], u * u * u * p0[1] + 3 * u * u * t * p1[1] + 3 * u * t * t * p2[1] + t * t * t * p3[1]]); } }
|
|
233
|
+
function trace(ctx, pts, closed = true) { ctx.beginPath(); pts.forEach(([x, y], i) => i ? ctx.lineTo(x, y) : ctx.moveTo(x, y)); if (closed) ctx.closePath(); }
|
|
234
|
+
function fill(ctx, pts, color, dx = 0, dy = 0) { ctx.fillStyle = color; ctx.beginPath(); pts.forEach(([x, y], i) => i ? ctx.lineTo(x + dx, y + dy) : ctx.moveTo(x + dx, y + dy)); ctx.closePath(); ctx.fill(); }
|
|
235
|
+
// a key line: a ribbon whose width swells and thins along the path, the way a cut line prints
|
|
236
|
+
function ink(ctx, pts, w, color, seed = 0, closed = true) {
|
|
237
|
+
const n = pts.length; if (n < 2) return;
|
|
238
|
+
const L = [], R = [];
|
|
239
|
+
for (let i = 0; i < n; i++) {
|
|
240
|
+
const a = pts[closed ? (i - 1 + n) % n : Math.max(0, i - 1)], b = pts[closed ? (i + 1) % n : Math.min(n - 1, i + 1)];
|
|
241
|
+
let dx = b[0] - a[0], dy = b[1] - a[1]; const l = Math.hypot(dx, dy) || 1; dx /= l; dy /= l;
|
|
242
|
+
let ww = w * (0.62 + 0.75 * hash(seed + Math.floor(i / 2) * 1.37));
|
|
243
|
+
if (!closed) ww *= Math.min(1, 0.35 + Math.min(i, n - 1 - i) * 0.35);
|
|
244
|
+
L.push([pts[i][0] - dy * ww / 2, pts[i][1] + dx * ww / 2]); R.push([pts[i][0] + dy * ww / 2, pts[i][1] - dx * ww / 2]);
|
|
245
|
+
}
|
|
246
|
+
ctx.fillStyle = color; ctx.beginPath();
|
|
247
|
+
L.forEach(([x, y], i) => i ? ctx.lineTo(x, y) : ctx.moveTo(x, y));
|
|
248
|
+
if (closed) { ctx.closePath(); ctx.moveTo(R[n - 1][0], R[n - 1][1]); for (let i = n - 2; i >= 0; i--) ctx.lineTo(R[i][0], R[i][1]); ctx.closePath(); ctx.fill('evenodd'); return; }
|
|
249
|
+
for (let i = n - 1; i >= 0; i--) ctx.lineTo(R[i][0], R[i][1]);
|
|
250
|
+
ctx.closePath(); ctx.fill();
|
|
251
|
+
}
|
|
252
|
+
// a gouge: fat where the tool goes in, sharp where it comes out
|
|
253
|
+
function gouge(ctx, x0, y0, x1, y1, w) {
|
|
254
|
+
const dx = x1 - x0, dy = y1 - y0, l = Math.hypot(dx, dy) || 1, nx = -dy / l * w / 2, ny = dx / l * w / 2;
|
|
255
|
+
ctx.moveTo(x0 + nx, y0 + ny);
|
|
256
|
+
ctx.quadraticCurveTo(x0 + dx * 0.4 + nx * 0.85, y0 + dy * 0.4 + ny * 0.85, x1, y1);
|
|
257
|
+
ctx.quadraticCurveTo(x0 + dx * 0.4 - nx * 0.85, y0 + dy * 0.4 - ny * 0.85, x0 - nx, y0 - ny);
|
|
258
|
+
ctx.closePath();
|
|
259
|
+
}
|
|
260
|
+
function cut(ctx, color, x0, y0, x1, y1, w) { ctx.fillStyle = color; ctx.beginPath(); gouge(ctx, x0, y0, x1, y1, w); ctx.fill(); }
|
|
261
|
+
// ink never prints solid: knock small specks of paper out of what has been printed so far
|
|
262
|
+
function speckle(ctx, x, y, w, h, density, seed, size = 1) {
|
|
263
|
+
ctx.save(); ctx.globalCompositeOperation = 'destination-out'; ctx.fillStyle = '#000';
|
|
264
|
+
const n = Math.floor(w * h * density);
|
|
265
|
+
for (let i = 0; i < n; i++) { const px = x + hash(seed + i * 1.13) * w, py = y + hash(seed + i * 2.71 + 9) * h; ctx.globalAlpha = 0.25 + hash(seed + i * 5.3) * 0.6; ctx.fillRect(px, py, size * (0.6 + hash(i + seed) * 1.2), size * 0.8); }
|
|
266
|
+
ctx.restore();
|
|
267
|
+
}
|
|
268
|
+
const REG = 2.4; // the colour block lands a hair off the key block, as it does on a real press
|
|
269
|
+
|
|
270
|
+
function canvas(w, h, dpr) {
|
|
271
|
+
const c = document.createElement('canvas'); c.width = Math.ceil(w * dpr); c.height = Math.ceil(h * dpr);
|
|
272
|
+
const g = c.getContext('2d'); g.scale(dpr, dpr); c.w = w; c.h = h; return [c, g];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---------------------------------------------------------------- the hedgehog
|
|
276
|
+
// body sprite: spines, quills and key line. Origin (ox, oy) is the body centre.
|
|
277
|
+
function hogBody(r, P, dpr, seed) {
|
|
278
|
+
const W = r * 2.8, H = r * 2.8, ox = W / 2, oy = H / 2, [c, g] = canvas(W, H, dpr);
|
|
279
|
+
const outline = spikePts(ox, oy, r, r * 1.06, 19, 0.9, 1.12, seed);
|
|
280
|
+
fill(g, outline, P.spine, REG, REG * 0.6);
|
|
281
|
+
// quills: rings of gouges flowing back from the brow; the top ones catch the sun
|
|
282
|
+
const rings = [[0.4, 0.68, 12, 0.075], [0.58, 0.88, 15, 0.068], [0.76, 1.03, 19, 0.058]];
|
|
283
|
+
rings.forEach(([d0, d1, n, w], ri) => {
|
|
284
|
+
for (let k = 0; k < n; k++) {
|
|
285
|
+
const a = Math.PI * (0.88 + 1.24 * (k + (ri % 2 ? 0.5 : 0)) / (n - 0.5)) + (hash(seed + k * 3 + ri * 50) - 0.5) * 0.1, bend = 0.13 * Math.cos(a);
|
|
286
|
+
cut(g, P.quill,
|
|
287
|
+
ox + Math.cos(a) * r * d0, oy + Math.sin(a) * r * d0 * 1.05, ox + Math.cos(a + bend) * r * d1, oy + Math.sin(a + bend) * r * d1 * 1.05, r * w);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
speckle(g, 0, 0, W, H, 0.05, seed + 3, Math.max(1, r * 0.03));
|
|
291
|
+
ink(g, outline, Math.max(2, r * 0.07), P.line, seed + 1);
|
|
292
|
+
return {c, ox, oy};
|
|
293
|
+
}
|
|
294
|
+
// the face, without eyes and nose (those are drawn live: they blink, squint and sniff)
|
|
295
|
+
function hogFace(r, P, dpr, seed) {
|
|
296
|
+
const W = r * 2, H = r * 1.9, ox = W / 2, oy = r * 0.75, [c, g] = canvas(W, H, dpr);
|
|
297
|
+
const x = ox, fy = oy, pts = [[x, fy - r * 0.38]];
|
|
298
|
+
bez(pts, [x, fy - r * 0.38], [x + r * 0.44, fy - r * 0.62], [x + r * 0.8, fy - r * 0.2], [x + r * 0.6, fy + r * 0.14]);
|
|
299
|
+
bez(pts, [x + r * 0.6, fy + r * 0.14], [x + r * 0.46, fy + r * 0.42], [x + r * 0.3, fy + r * 0.52], [x + r * 0.2, fy + r * 0.66], 6);
|
|
300
|
+
bez(pts, [x + r * 0.2, fy + r * 0.66], [x + r * 0.08, fy + r * 0.84], [x - r * 0.08, fy + r * 0.84], [x - r * 0.2, fy + r * 0.66], 6);
|
|
301
|
+
bez(pts, [x - r * 0.2, fy + r * 0.66], [x - r * 0.3, fy + r * 0.52], [x - r * 0.46, fy + r * 0.42], [x - r * 0.6, fy + r * 0.14], 6);
|
|
302
|
+
bez(pts, [x - r * 0.6, fy + r * 0.14], [x - r * 0.8, fy - r * 0.2], [x - r * 0.44, fy - r * 0.62], [x, fy - r * 0.38]);
|
|
303
|
+
pts.pop();
|
|
304
|
+
for (const s of [-1, 1]) { // ears
|
|
305
|
+
const e = ellipsePts(x + s * r * 0.6, fy - r * 0.34, r * 0.16, r * 0.15, 14, seed + s);
|
|
306
|
+
fill(g, e, P.face, REG, REG * 0.5); fill(g, ellipsePts(x + s * r * 0.6, fy - r * 0.32, r * 0.07, r * 0.07, 10), P.blush);
|
|
307
|
+
ink(g, e, Math.max(1.6, r * 0.05), P.line, seed + 7 + s);
|
|
308
|
+
}
|
|
309
|
+
fill(g, pts, P.face, REG, REG * 0.5);
|
|
310
|
+
for (const s of [-1, 1]) cut(g, P.faceCut, x + s * r * 0.44, fy + r * 0.1, x + s * r * 0.24, fy + r * 0.5, r * 0.055);
|
|
311
|
+
for (const s of [-1, 1]) fill(g, ellipsePts(x + s * r * 0.4, fy + r * 0.22, r * 0.11, r * 0.07, 12), P.blush);
|
|
312
|
+
// the brow: the quills come down to a peak between the eyes
|
|
313
|
+
fill(g, [[x - r * 0.38, fy - r * 0.54], [x - r * 0.2, fy - r * 0.3], [x - r * 0.1, fy - r * 0.42], [x, fy - r * 0.2], [x + r * 0.1, fy - r * 0.42], [x + r * 0.2, fy - r * 0.3], [x + r * 0.38, fy - r * 0.54]], P.spine);
|
|
314
|
+
speckle(g, 0, 0, W, H, 0.025, seed + 11, Math.max(1, r * 0.025));
|
|
315
|
+
ink(g, pts, Math.max(2, r * 0.065), P.line, seed + 2);
|
|
316
|
+
return {c, ox, oy};
|
|
317
|
+
}
|
|
318
|
+
// eyes and nose, live. state: 'idle' | 'blink' | 'boop'
|
|
319
|
+
function hogEyes(ctx, x, fy, r, P, state, look, sniff) {
|
|
320
|
+
ctx.fillStyle = P.ink; ctx.strokeStyle = P.ink; ctx.lineWidth = r * 0.085; ctx.lineCap = 'round'; ctx.lineJoin = 'round';
|
|
321
|
+
const lk = (look || 0) * r * 0.05;
|
|
322
|
+
for (const s of [-1, 1]) {
|
|
323
|
+
const ex = x + s * r * 0.26 + lk, ey = fy - r * 0.04;
|
|
324
|
+
if (state === 'boop') { ctx.beginPath(); ctx.moveTo(ex - s * r * 0.08, ey - r * 0.09); ctx.lineTo(ex + s * r * 0.05, ey); ctx.lineTo(ex - s * r * 0.08, ey + r * 0.09); ctx.stroke(); }
|
|
325
|
+
else if (state === 'blink') { ctx.beginPath(); ctx.moveTo(ex - r * 0.08, ey); ctx.quadraticCurveTo(ex, ey + r * 0.06, ex + r * 0.08, ey); ctx.stroke(); }
|
|
326
|
+
else { ctx.beginPath(); ctx.ellipse(ex, ey, r * 0.085, r * 0.105, 0, 0, TAU); ctx.fill(); ctx.fillStyle = P.paper; ctx.beginPath(); ctx.arc(ex - r * 0.028, ey - r * 0.04, r * 0.034, 0, TAU); ctx.fill(); ctx.fillStyle = P.ink; }
|
|
327
|
+
}
|
|
328
|
+
const ny = fy + r * 0.64 + (sniff || 0) * r * 0.03;
|
|
329
|
+
ctx.beginPath(); ctx.ellipse(x, ny, r * 0.25, r * 0.18, 0, 0, TAU); ctx.fill();
|
|
330
|
+
ctx.fillStyle = P.paper; ctx.beginPath(); gouge(ctx, x - r * 0.15, ny - r * 0.02, x - r * 0.02, ny - r * 0.12, r * 0.07); ctx.fill();
|
|
331
|
+
ctx.beginPath(); ctx.arc(x + r * 0.1, ny + r * 0.05, r * 0.03, 0, TAU); ctx.fill();
|
|
332
|
+
if (state === 'boop') { ctx.fillStyle = P.ink; ctx.beginPath(); ctx.ellipse(x, ny + r * 0.27, r * 0.07, r * 0.085, 0, 0, TAU); ctx.fill(); }
|
|
333
|
+
}
|
|
334
|
+
function apple(r, P, dpr, seed) {
|
|
335
|
+
const ar = r * 0.38, W = ar * 3, H = ar * 3.2, ox = W / 2, oy = H * 0.58, [c, g] = canvas(W, H, dpr);
|
|
336
|
+
const body = ellipsePts(ox, oy, ar * 1.06, ar, 24, seed, 0.04);
|
|
337
|
+
fill(g, body, P.apple, REG, REG * 0.5);
|
|
338
|
+
cut(g, P.paper, ox - ar * 0.55, oy - ar * 0.05, ox - ar * 0.12, oy - ar * 0.6, ar * 0.24);
|
|
339
|
+
ink(g, body, Math.max(1.8, r * 0.06), P.line, seed);
|
|
340
|
+
ink(g, [[ox, oy - ar * 0.85], [ox + ar * 0.06, oy - ar * 1.1], [ox + ar * 0.14, oy - ar * 1.35]], Math.max(2.4, r * 0.08), P.line, seed + 3, false);
|
|
341
|
+
const leaf = [[ox + ar * 0.12, oy - ar * 1.1]]; bez(leaf, leaf[0], [ox + ar * 0.4, oy - ar * 1.55], [ox + ar * 0.9, oy - ar * 1.5], [ox + ar * 1.0, oy - ar * 1.25], 6); bez(leaf, [ox + ar * 1.0, oy - ar * 1.25], [ox + ar * 0.7, oy - ar * 1.0], [ox + ar * 0.4, oy - ar * 1.0], [ox + ar * 0.12, oy - ar * 1.1], 6);
|
|
342
|
+
fill(g, leaf, P.leaf); ink(g, leaf, 1.6, P.line, seed + 5);
|
|
343
|
+
return {c, ox, oy};
|
|
344
|
+
}
|
|
345
|
+
// the tuck: a hedgehog that waited too long rolls into a ball and drops away
|
|
346
|
+
function ball(r, P, dpr, seed) {
|
|
347
|
+
const R = r * 0.95, W = R * 3, H = R * 3, ox = W / 2, oy = H / 2, [c, g] = canvas(W, H, dpr);
|
|
348
|
+
const outline = spikePts(ox, oy, R, R * 0.96, 20, 0.8, 1.14, seed);
|
|
349
|
+
fill(g, outline, P.spine, REG, REG * 0.6);
|
|
350
|
+
for (let k = 0; k < 16; k++) { const a = TAU * k / 16 + 0.2; cut(g, P.quill, ox + Math.cos(a) * R * 0.3, oy + Math.sin(a) * R * 0.3, ox + Math.cos(a) * R * 0.9, oy + Math.sin(a) * R * 0.9, R * 0.1); }
|
|
351
|
+
speckle(g, 0, 0, W, H, 0.04, seed + 9, Math.max(1, r * 0.03));
|
|
352
|
+
ink(g, outline, Math.max(2.2, r * 0.07), P.line, seed + 4);
|
|
353
|
+
return {c, ox, oy, R};
|
|
354
|
+
}
|
|
355
|
+
// the wasp: a ground wasp climbing out of the burrow. Stripes are the one warning everyone
|
|
356
|
+
// already knows; the hedgehogs are soft and cream, the wasp is hard, banded and buzzing.
|
|
357
|
+
// Origin is the head; wings are separate so they can whirr.
|
|
358
|
+
function wasp(r, P, dpr, seed) {
|
|
359
|
+
const W = r * 2.4, H = r * 3.4, ox = W / 2, oy = r * 0.75, [c, g] = canvas(W, H, dpr), x = ox, hy = oy;
|
|
360
|
+
// abdomen: a pinched waist, bands, and a hooked sting
|
|
361
|
+
const ay = hy + r * 1.05, ab = [[x, ay]];
|
|
362
|
+
bez(ab, [x, ay], [x + r * 0.44, ay + r * 0.02], [x + r * 0.42, ay + r * 0.8], [x + r * 0.07, ay + r * 1.22], 12);
|
|
363
|
+
bez(ab, [x + r * 0.07, ay + r * 1.22], [x - r * 0.06, ay + r * 1.3], [x - r * 0.24, ay + r * 1.1], [x - r * 0.32, ay + r * 0.8], 6);
|
|
364
|
+
bez(ab, [x - r * 0.32, ay + r * 0.8], [x - r * 0.46, ay + r * 0.45], [x - r * 0.4, ay], [x, ay], 8); ab.pop();
|
|
365
|
+
const sting = [[x + r * 0.02, ay + r * 1.2], [x + r * 0.09, ay + r * 1.5], [x - r * 0.06, ay + r * 1.62], [x - r * 0.01, ay + r * 1.48], [x - r * 0.06, ay + r * 1.24]];
|
|
366
|
+
fill(g, sting, P.waspInk); ink(g, sting, Math.max(1.6, r * 0.04), P.line, seed + 9);
|
|
367
|
+
fill(g, ab, P.wasp, REG, REG * 0.5);
|
|
368
|
+
g.save(); trace(g, ab); g.clip();
|
|
369
|
+
for (let b = 0; b < 4; b++) { const by = ay + r * (0.2 + b * 0.27); fill(g, [[x - r, by + r * 0.06], [x + r, by - r * 0.02], [x + r, by + r * 0.12], [x - r, by + r * 0.2]], P.waspInk); }
|
|
370
|
+
g.restore();
|
|
371
|
+
speckle(g, 0, ay, W, r * 1.4, 0.03, seed + 2, Math.max(1, r * 0.03));
|
|
372
|
+
ink(g, ab, Math.max(2, r * 0.075), P.line, seed + 1);
|
|
373
|
+
// the waist and thorax
|
|
374
|
+
fill(g, ellipsePts(x, ay - r * 0.04, r * 0.09, r * 0.1, 10), P.waspInk);
|
|
375
|
+
const th = ellipsePts(x, hy + r * 0.6, r * 0.34, r * 0.3, 22, seed + 2, 0.03);
|
|
376
|
+
fill(g, th, P.waspInk);
|
|
377
|
+
cut(g, P.wasp, x - r * 0.3, hy + r * 0.52, x - r * 0.06, hy + r * 0.44, r * 0.1); cut(g, P.wasp, x + r * 0.3, hy + r * 0.52, x + r * 0.06, hy + r * 0.44, r * 0.1);
|
|
378
|
+
ink(g, th, Math.max(2, r * 0.065), P.line, seed + 3);
|
|
379
|
+
// head, lowered: a hard wedge with a black anchor mark, kidney eyes, open mandibles
|
|
380
|
+
const hd = [[x - r * 0.46, hy - r * 0.18], [x - r * 0.3, hy - r * 0.36], [x + r * 0.3, hy - r * 0.36], [x + r * 0.46, hy - r * 0.18], [x + r * 0.3, hy + r * 0.24], [x, hy + r * 0.34], [x - r * 0.3, hy + r * 0.24]];
|
|
381
|
+
fill(g, hd, P.wasp, REG, REG * 0.5);
|
|
382
|
+
fill(g, [[x - r * 0.1, hy - r * 0.3], [x + r * 0.1, hy - r * 0.3], [x + r * 0.04, hy + r * 0.04], [x + r * 0.12, hy + r * 0.12], [x, hy + r * 0.2], [x - r * 0.12, hy + r * 0.12], [x - r * 0.04, hy + r * 0.04]], P.waspInk);
|
|
383
|
+
for (const s of [-1, 1]) {
|
|
384
|
+
const eye = [[x + s * r * 0.16, hy - r * 0.3], [x + s * r * 0.42, hy - r * 0.22], [x + s * r * 0.36, hy + r * 0.12], [x + s * r * 0.22, hy + r * 0.04]];
|
|
385
|
+
fill(g, eye, P.waspInk); cut(g, P.waspEye, x + s * r * 0.22, hy - r * 0.12, x + s * r * 0.34, hy - r * 0.08, r * 0.09);
|
|
386
|
+
ink(g, [[x + s * r * 0.06, hy - r * 0.12], [x + s * r * 0.24, hy - r * 0.3], [x + s * r * 0.46, hy - r * 0.34]], Math.max(3, r * 0.1), P.waspInk, seed + 12 + s, false);
|
|
387
|
+
ink(g, [[x + s * r * 0.1, hy + r * 0.3], [x + s * r * 0.2, hy + r * 0.46], [x + s * r * 0.05, hy + r * 0.54]], Math.max(2.2, r * 0.08), P.line, seed + 6, false);
|
|
388
|
+
ink(g, [[x + s * r * 0.08, hy - r * 0.34], [x + s * r * 0.2, hy - r * 0.62], [x + s * r * 0.42, hy - r * 0.7], [x + s * r * 0.56, hy - r * 0.58]], Math.max(2.4, r * 0.075), P.line, seed + 7, false);
|
|
389
|
+
}
|
|
390
|
+
ink(g, hd, Math.max(2, r * 0.07), P.line, seed + 8);
|
|
391
|
+
return {c, ox, oy};
|
|
392
|
+
}
|
|
393
|
+
function wing(r, P, dpr, seed) { // one wing: long, narrow, angular and smoky; mirrored for the other
|
|
394
|
+
const W = r * 1.5, H = r * 1.2, ox = W * 0.06, oy = H * 0.85, [c, g] = canvas(W, H, dpr);
|
|
395
|
+
const pts = [[ox, oy], [ox + r * 0.5, oy - r * 0.62], [ox + r * 1.28, oy - r * 0.86], [ox + r * 1.34, oy - r * 0.68], [ox + r * 0.62, oy - r * 0.18]];
|
|
396
|
+
fill(g, pts, P.wing);
|
|
397
|
+
for (let k = 0; k < 4; k++) cut(g, P.line, ox + r * (0.4 + k * 0.22), oy - r * (0.3 + k * 0.12), ox + r * (0.55 + k * 0.22), oy - r * (0.5 + k * 0.1), Math.max(1, r * 0.02));
|
|
398
|
+
ink(g, [[ox + r * 0.1, oy - r * 0.1], [ox + r * 0.7, oy - r * 0.55], [ox + r * 1.2, oy - r * 0.75]], Math.max(1.4, r * 0.03), P.line, seed + 2, false);
|
|
399
|
+
ink(g, pts, Math.max(1.6, r * 0.045), P.line, seed);
|
|
400
|
+
return {c, ox, oy};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// ---------------------------------------------------------------- the burrow
|
|
404
|
+
// spoil heaped behind a black, gouge-rimmed hole; grass in front that the hedgehog rises behind
|
|
405
|
+
function heap(h, P, dpr) {
|
|
406
|
+
const {rx, ry} = h, W = rx * 2.4, H = ry * 4.6, ox = W / 2, oy = H * 0.62, [c, g] = canvas(W, H, dpr), sd = h.i * 37 + 5;
|
|
407
|
+
const hy = oy - ry * 0.5, mound = ellipsePts(ox, hy, rx * 1.02, ry * 1.25, 28, sd, 0.07);
|
|
408
|
+
fill(g, mound, P.soil, REG, REG * 0.5);
|
|
409
|
+
for (let k = 0; k < 6; k++) { // striations cut along the slope of the rim, following its curve
|
|
410
|
+
const a = Math.PI * (1.08 + 0.84 * k / 5), px = ox + Math.cos(a) * rx * 0.86, py = hy + Math.sin(a) * ry * 1.02;
|
|
411
|
+
cut(g, P.soilCut, px, py, px + Math.cos(a + 1.5) * rx * 0.24, py + Math.sin(a + 1.5) * ry * 0.3, ry * 0.15);
|
|
412
|
+
}
|
|
413
|
+
speckle(g, 0, 0, W, H * 0.7, 0.05, sd + 5, Math.max(1, rx * 0.02));
|
|
414
|
+
ink(g, mound, Math.max(2.2, rx * 0.045), P.line, sd + 2);
|
|
415
|
+
const hole = ellipsePts(ox, oy, rx * 0.8, ry * 0.78, 28, sd + 3, 0.03);
|
|
416
|
+
fill(g, hole, P.ink);
|
|
417
|
+
// the far wall of the hole catches a little light; the near side falls into black
|
|
418
|
+
g.save(); trace(g, hole); g.clip();
|
|
419
|
+
fill(g, ellipsePts(ox, oy - ry * 0.62, rx * 0.84, ry * 0.5, 20, sd + 4, 0.06), P.soilDeep);
|
|
420
|
+
g.restore();
|
|
421
|
+
return {c, ox, oy};
|
|
422
|
+
}
|
|
423
|
+
function front(h, P, dpr) { // the near lip of the crater: soil over whatever is in the hole, turf below
|
|
424
|
+
const {rx, ry} = h, hw = rx * 0.8, hr = ry * 0.78, W = rx * 2.4, H = ry * 3.2, ox = W / 2, oy = ry * 1.1, [c, g] = canvas(W, H, dpr);
|
|
425
|
+
const inner = ellipsePts(ox, oy + hr * 0.12, hw * 1.0, hr * 0.62, 24, h.i * 5, 0.03, 0, Math.PI);
|
|
426
|
+
const outer = ellipsePts(ox, oy + hr * 0.2, rx * 1.02, hr * 1.25, 24, h.i * 7, 0.05, 0, Math.PI);
|
|
427
|
+
const lip = [...inner, ...outer.slice().reverse()];
|
|
428
|
+
fill(g, [[ox + rx * 1.1, oy + hr * 0.2], ...outer, [ox - rx * 1.1, oy + hr * 0.2], [ox - rx * 1.1, oy + hr * 2.2], [ox + rx * 1.1, oy + hr * 2.2]], P.lawn);
|
|
429
|
+
fill(g, lip, P.soil, REG * 0.5, REG * 0.3);
|
|
430
|
+
for (let k = 0; k < 4; k++) { const a = Math.PI * (0.2 + 0.6 * k / 3), px = ox + Math.cos(a) * hw * 0.98, py = oy + hr * 0.3 + Math.sin(a) * hr * 0.75; cut(g, P.soilCut, px - hw * 0.1, py, px + hw * 0.1, py + hr * 0.08, hr * 0.18); }
|
|
431
|
+
ink(g, inner, Math.max(2.2, rx * 0.045), P.line, h.i * 13, false);
|
|
432
|
+
ink(g, outer, Math.max(2.2, rx * 0.045), P.line, h.i * 17, false);
|
|
433
|
+
for (const s of [-1, 1]) { const tx = ox + s * rx * 0.95, ty = oy + hr * 0.9; for (const d of [-1, 0, 1]) cut(g, P.tick, tx + d * 3, ty + 4, tx + d * 5, ty - 6 - (d ? 0 : 3), 2.4); }
|
|
434
|
+
return {c, ox, oy};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// ---------------------------------------------------------------- the static ground
|
|
438
|
+
function hedgeProfile(W, seed) { // the hedge top: lumps of every size, as a careless gardener left it
|
|
439
|
+
const lumps = [];
|
|
440
|
+
for (let x = -30, i = 0; x < W + 60; i++) {
|
|
441
|
+
const big = hash(seed + i * 7) > 0.8, r = 13 + hash(seed + i * 13) * 15 + (big ? 16 : 0);
|
|
442
|
+
lumps.push({x: x + r, r, h: r * (0.7 + hash(seed + i * 3) * 0.5)}); x += r * (1.15 + hash(seed + i * 5) * 0.6);
|
|
443
|
+
}
|
|
444
|
+
return x => { let y = 0; for (const l of lumps) { const d = (x - l.x) / l.r; if (d > -1 && d < 1) y = Math.max(y, Math.sqrt(1 - d * d) * l.h); } return y; };
|
|
445
|
+
}
|
|
446
|
+
function ground(L, P, dpr) { // the tree, hedge, flowers and lawn: printed once
|
|
447
|
+
const {W, H, skyH} = L, [c, g] = canvas(W, H, dpr);
|
|
448
|
+
// apple tree behind the hedge, on the right - it is where the apples come from
|
|
449
|
+
const tx = W * 0.95, tr = Math.min(60, skyH * 0.4), ty = skyH - tr * 0.55;
|
|
450
|
+
const crown = [];
|
|
451
|
+
if (!L.tall) {
|
|
452
|
+
for (let k = 0; k < 7; k++) crown.push(ellipsePts(tx + Math.cos(k * 0.9) * tr * 0.55, ty - tr * 0.2 + Math.sin(k * 0.9) * tr * 0.35, tr * 0.55, tr * 0.48, 16, 300 + k, 0.08));
|
|
453
|
+
crown.forEach(p => ink(g, p, 4, P.line, 7));
|
|
454
|
+
crown.forEach(p => fill(g, p, P.hedge));
|
|
455
|
+
for (let k = 0; k < 26; k++) { const a = hash(k + 300) * TAU, d = hash(k + 330) * tr * 0.85; cut(g, P.nick, tx + Math.cos(a) * d, ty - tr * 0.2 + Math.sin(a) * d * 0.6, tx + Math.cos(a) * d + 8, ty - tr * 0.2 + Math.sin(a) * d * 0.6 - 4, 3); }
|
|
456
|
+
for (let k = 0; k < 7; k++) { const e = ellipsePts(tx + (hash(k * 3 + 80) - 0.5) * tr * 1.7, ty - tr * 0.45 + hash(k * 5 + 81) * tr * 0.7, 4.4, 4.2, 10); fill(g, e, P.apple); ink(g, e, 1.6, P.line, k); }
|
|
457
|
+
}
|
|
458
|
+
// the hedge
|
|
459
|
+
const prof = hedgeProfile(W, 11), top = [];
|
|
460
|
+
for (let x = -4; x <= W + 4; x += 4) top.push([x, skyH - 8 - prof(x)]);
|
|
461
|
+
const hedge = [...top, [W + 4, skyH + 14], [-4, skyH + 14]];
|
|
462
|
+
fill(g, hedge, P.hedge);
|
|
463
|
+
// leaves: rows of nicks following the hedge's curve
|
|
464
|
+
for (let row = 0; row < 5; row++) for (let x = 6 + row * 5; x < W; x += 11 + hash(row * 50 + x) * 8) {
|
|
465
|
+
const yTop = skyH - 8 - prof(x), y = yTop + 7 + row * ((skyH + 6 - yTop) / 5) + (hash(x + row) - 0.5) * 4;
|
|
466
|
+
if (y > skyH + 4) continue;
|
|
467
|
+
const a = -0.6 + (hash(x * 3 + row) - 0.5) * 0.8;
|
|
468
|
+
cut(g, P.nick, x, y, x + Math.cos(a) * 8, y + Math.sin(a) * 8, 3.2);
|
|
469
|
+
}
|
|
470
|
+
speckle(g, 0, skyH - 60, W, 80, 0.03, 21, 1.2);
|
|
471
|
+
ink(g, top, 3, P.line, 5, false);
|
|
472
|
+
// lawn: one ink, cut below in rows of V-nicks that open out towards us
|
|
473
|
+
g.fillStyle = P.lawn; g.fillRect(0, skyH + 10, W, H - skyH - 10);
|
|
474
|
+
// the bed at the hedge's foot
|
|
475
|
+
const bed = [[0, skyH + 6]]; for (let x = 0; x <= W + 20; x += 18) bed.push([x, skyH + 24 + Math.sin(x * 0.04) * 4 + hash(x) * 3]); bed.push([W, skyH + 6]);
|
|
476
|
+
for (let i = 0, x = 10; x < W; i++) { flower(g, x, skyH + 20, Math.floor(hash(i * 47) * 3), 0.8 + hash(i * 3) * 0.4, i, P); x += 24 + hash(i * 53) * 46; }
|
|
477
|
+
const bottom = H;
|
|
478
|
+
// the lawn is cut in long rows that follow the ground and open out towards us
|
|
479
|
+
let y = skyH + 38, row = 0;
|
|
480
|
+
while (y < bottom - 6) {
|
|
481
|
+
const t = (y - skyH) / (bottom - skyH), s = 0.5 + t * 1.2;
|
|
482
|
+
for (let x = -20 + hash(row * 17) * 40; x < W + 20;) {
|
|
483
|
+
const len = (18 + hash(row * 91 + x) * 46) * s, yy = y + Math.sin(x * 0.01 + row) * 3 * s;
|
|
484
|
+
const skip = L.holes.some(h => Math.abs(h.x - (x + len / 2)) < h.rx * 1.2 + len / 2 && yy > h.y - h.ry * 2.6 && yy < h.y + h.ry * 1.8);
|
|
485
|
+
if (!skip) cut(g, P.tick, x, yy, x + len, yy + (hash(x + row) - 0.5) * 3 * s, (2 + hash(x * 3 + row) * 1.6) * s);
|
|
486
|
+
x += len + (8 + hash(row * 13 + x) * 26) * s;
|
|
487
|
+
}
|
|
488
|
+
// now and then a tuft cut upright among the rows
|
|
489
|
+
for (let k = 0; k < W / 70; k++) {
|
|
490
|
+
const tx = hash(row * 300 + k) * W, ty = y + 3 * s;
|
|
491
|
+
if (L.holes.some(h => Math.abs(h.x - tx) < h.rx * 1.3 && ty > h.y - h.ry * 2.6 && ty < h.y + h.ry * 1.8)) continue;
|
|
492
|
+
for (const d of [-1, 0, 1]) cut(g, P.tick, tx + d * 3 * s, ty, tx + d * 5 * s, ty - (6 + (d ? 0 : 3)) * s, 2.2 * s);
|
|
493
|
+
}
|
|
494
|
+
y += (10 + t * 16); row++;
|
|
495
|
+
}
|
|
496
|
+
const side = (W - L.bw) / 2;
|
|
497
|
+
if (side > 90) for (const sd of [-1, 1]) sideHedge(g, L, P, sd, side);
|
|
498
|
+
speckle(g, 0, skyH, W, H - skyH, 0.012, 33, 1.3);
|
|
499
|
+
return c;
|
|
500
|
+
}
|
|
501
|
+
function flower(g, x, y, kind, s, i, P) {
|
|
502
|
+
const h = (9 + hash(i) * 14) * s, fx = x + (hash(i * 2) - 0.5) * 5, fy = y - h;
|
|
503
|
+
ink(g, [[x, y], [lerp(x, fx, 0.5), y - h * 0.5], [fx, fy]], 2.2 * s, P.hedge, i, false);
|
|
504
|
+
if (kind === 0) { const p = ellipsePts(fx, fy, 5.6 * s, 4.6 * s, 10, i, 0.14); fill(g, p, P.poppy); ink(g, p, 1.5, P.line, i); g.fillStyle = P.ink; g.beginPath(); g.arc(fx, fy, 1.6 * s, 0, TAU); g.fill(); }
|
|
505
|
+
else if (kind === 1) { const p = spikePts(fx, fy, 5.6 * s, 4.8 * s, 7, 0.62, 1, i); fill(g, p, P.mari); ink(g, p, 1.4, P.line, i); }
|
|
506
|
+
else { const p = ellipsePts(fx, fy, 4.6 * s, 4.4 * s, 10, i, 0.06); fill(g, p, P.daisy); ink(g, p, 1.3, P.line, i); g.fillStyle = P.mari; g.beginPath(); g.arc(fx, fy, 1.7 * s, 0, TAU); g.fill(); }
|
|
507
|
+
}
|
|
508
|
+
function sideHedge(g, L, P, sd, side) { // a wide screen gets the garden walled in by hedge on both sides
|
|
509
|
+
const {W, H, skyH} = L, x0 = sd < 0 ? 0 : W, bottom = H;
|
|
510
|
+
const inner = y => x0 - sd * side * lerp(0.42, 0.24, (y - skyH) / (bottom - skyH));
|
|
511
|
+
const prof = hedgeProfile(H, 40 + sd), edge = [];
|
|
512
|
+
for (let y = skyH - 10; y <= bottom + 4; y += 4) edge.push([inner(y) - sd * prof(y) * 0.8, y]);
|
|
513
|
+
const shape = [[x0, skyH - 10], ...edge, [x0, bottom + 4]];
|
|
514
|
+
fill(g, shape, P.hedge);
|
|
515
|
+
for (let k = 0; k < (bottom - skyH) / 5; k++) {
|
|
516
|
+
const y = skyH + hash(k * 7 + sd) * (bottom - skyH), xi = inner(y) - sd * prof(y) * 0.8, x = xi + sd * (6 + hash(k * 3 + sd) * Math.abs(x0 - xi) * 0.9);
|
|
517
|
+
cut(g, P.nick, x, y, x + sd * 8, y - 5, 3.2);
|
|
518
|
+
}
|
|
519
|
+
ink(g, edge, 3, P.line, 9 + sd, false);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// one ink mottle for the whole print: paper breaking through where the roller ran thin
|
|
523
|
+
let mottleTile = null;
|
|
524
|
+
function mottle(ctx, W, H) {
|
|
525
|
+
if (!mottleTile) {
|
|
526
|
+
const N = 256, [c, g] = canvas(N, N, 1), img = g.createImageData(N, N), d = img.data;
|
|
527
|
+
const vn = (x, y, f, sd) => { const xi = Math.floor(x * f), yi = Math.floor(y * f), xf = x * f - xi, yf = y * f - yi, m = f; const h2 = (a, b) => hash(((a % m + m) % m) * 7.13 + ((b % m + m) % m) * 131.7 + sd); const u = xf * xf * (3 - 2 * xf), v = yf * yf * (3 - 2 * yf); return lerp(lerp(h2(xi, yi), h2(xi + 1, yi), u), lerp(h2(xi, yi + 1), h2(xi + 1, yi + 1), u), v); };
|
|
528
|
+
for (let y = 0; y < N; y++) for (let x = 0; x < N; x++) {
|
|
529
|
+
const i = (y * N + x) * 4, n = vn(x / N, y / N, 8, 1) * 0.6 + vn(x / N, y / N, 32, 2) * 0.4, sp = hash(i * 0.37 + 5);
|
|
530
|
+
const a = Math.max(0, n - 0.55) * 0.5 + (sp > 0.985 ? 0.35 : 0);
|
|
531
|
+
d[i] = 243; d[i + 1] = 233; d[i + 2] = 211; d[i + 3] = Math.round(a * 255);
|
|
532
|
+
if (sp < 0.012) { d[i] = d[i + 1] = d[i + 2] = 20; d[i + 3] = 50; }
|
|
533
|
+
}
|
|
534
|
+
g.putImageData(img, 0, 0); mottleTile = c;
|
|
535
|
+
}
|
|
536
|
+
ctx.save(); ctx.fillStyle = ctx.createPattern(mottleTile, 'repeat'); ctx.fillRect(0, 0, W, H); ctx.restore();
|
|
537
|
+
}
|
|
538
|
+
return {mottle, INKS, TAU, lerp, clamp, mix, rgba, hash, ellipsePts, spikePts, trace, fill, ink, gouge, cut, speckle, canvas, REG,
|
|
539
|
+
hogBody, hogFace, hogEyes, apple, ball, wasp, wing, heap, front, ground, hedgeProfile};
|
|
540
|
+
})();
|
|
541
|
+
// Prickle Patch - placing the print: layout, the sky and the sun's road, each burrow and what is in it.
|
|
542
|
+
const Scene = (() => {
|
|
543
|
+
const {TAU, lerp, clamp, mix, rgba, hash, ellipsePts, spikePts, fill, gouge, cut} = Art;
|
|
544
|
+
|
|
545
|
+
function layout(W, H) {
|
|
546
|
+
const tall = H / W > 1.45;
|
|
547
|
+
const skyH = Math.round(clamp(H * (tall ? 0.22 : 0.2), 110, 210));
|
|
548
|
+
const LH = H - skyH, pad = tall ? 74 : 64; // the tags sit under the burrows
|
|
549
|
+
const bw = Math.min(W - 32, 1000, (LH - pad) * (tall ? 1.45 : 1.62));
|
|
550
|
+
const cell = bw / 3;
|
|
551
|
+
const backY = skyH + (LH - pad) * (tall ? 0.22 : 0.3), frontY = skyH + (LH - pad) * (tall ? 0.9 : 0.88);
|
|
552
|
+
const gap = (frontY - backY) / 2;
|
|
553
|
+
const R = Math.min(cell * 0.36, gap * (tall ? 0.38 : 0.38)), scales = tall ? [0.82, 0.91, 1] : [0.72, 0.86, 1], holes = [];
|
|
554
|
+
for (let r = 0; r < 3; r++) for (let c = 0; c < 3; c++) {
|
|
555
|
+
const s = scales[r];
|
|
556
|
+
holes.push({i: r * 3 + c, row: r, col: c, x: W / 2 + (c - 1) * cell * (0.72 + 0.28 * s), y: backY + r * gap, s,
|
|
557
|
+
r: R * s, rx: R * 1.42 * s, ry: R * 1.42 * s * 0.42});
|
|
558
|
+
}
|
|
559
|
+
return {W, H, skyH, LH, cell, bw, gap, holes, tall};
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// ---- sprites and the still parts of the print, made once per layout and per ink run
|
|
563
|
+
let S = null;
|
|
564
|
+
function bind(ctx) { if (S) S.ctx = ctx; }
|
|
565
|
+
function build(L, dpr) {
|
|
566
|
+
const runs = {};
|
|
567
|
+
for (const run of ['dusk', 'night']) {
|
|
568
|
+
const P = Art.INKS[run], rows = [0, 1, 2].map(row => {
|
|
569
|
+
const r = L.holes[row * 3].r;
|
|
570
|
+
return {bodies: [0, 1, 2].map(k => Art.hogBody(r, P, dpr, 17 + k * 31 + row * 7)), face: Art.hogFace(r, P, dpr, 5 + row),
|
|
571
|
+
apple: Art.apple(r, P, dpr, 3 + row), wasp: Art.wasp(r, P, dpr, 41 + row), wing: Art.wing(r, P, dpr, 51 + row), tuck: Art.ball(r, P, dpr, 61 + row)};
|
|
572
|
+
});
|
|
573
|
+
runs[run] = {P, rows, heaps: L.holes.map(h => Art.heap(h, P, dpr)), fronts: L.holes.map(h => Art.front(h, P, dpr)),
|
|
574
|
+
sky: skyLayer(L, run, dpr), ground: Art.ground(L, P, dpr)};
|
|
575
|
+
}
|
|
576
|
+
S = {L, runs, ctx: S ? S.ctx : null};
|
|
577
|
+
return S;
|
|
578
|
+
}
|
|
579
|
+
const put = (ctx, sp, x, y) => ctx.drawImage(sp.c, x - sp.ox, y - sp.oy, sp.c.w, sp.c.h);
|
|
580
|
+
// night 0: the dusk print; 1: the night print; in between, the two laid over each other
|
|
581
|
+
// between the two the night ink is rolled down over the dusk print like a brayer across a block
|
|
582
|
+
function each(night, fn) {
|
|
583
|
+
if (night <= 0) return fn(S.runs.dusk, 1);
|
|
584
|
+
if (night >= 1) return fn(S.runs.night, 1);
|
|
585
|
+
fn(S.runs.dusk, 1);
|
|
586
|
+
const y = rollerY(night); ctx0save(); S.ctx.beginPath(); S.ctx.rect(-50, -50, S.L.W + 100, y + 50); S.ctx.clip(); fn(S.runs.night, 1); S.ctx.restore();
|
|
587
|
+
}
|
|
588
|
+
const rollerY = night => -20 + (S.L.H + 60) * night;
|
|
589
|
+
function ctx0save() { S.ctx.save(); }
|
|
590
|
+
function roller(ctx, night) { // the brayer's edge: a dark lip of ink
|
|
591
|
+
if (night <= 0 || night >= 1) return;
|
|
592
|
+
const y = rollerY(night);
|
|
593
|
+
ctx.fillStyle = Art.INKS.night.ink; ctx.fillRect(0, y - 3, S.L.W, 9);
|
|
594
|
+
ctx.fillStyle = 'rgba(13,15,25,0.35)'; ctx.fillRect(0, y + 6, S.L.W, 10);
|
|
595
|
+
}
|
|
596
|
+
const inkOf = night => mix(Art.INKS.dusk.ink, Art.INKS.night.ink, night);
|
|
597
|
+
const pal = (night, key) => mix(Art.INKS.dusk[key], Art.INKS.night[key], night);
|
|
598
|
+
|
|
599
|
+
// ---- the sky: level bands cut with streaks and flat cloud banks; at night, stars and a moon
|
|
600
|
+
function skyLayer(L, run, dpr) {
|
|
601
|
+
const {W, skyH} = L, P = Art.INKS[run], night = run === 'night', [c, g] = Art.canvas(W, skyH + 8, dpr);
|
|
602
|
+
for (let b = 0; b < 4; b++) {
|
|
603
|
+
const y0 = skyH * (b / 4) * 0.95, pts = [[0, y0]];
|
|
604
|
+
for (let x = 0; x <= W + 30; x += 30) pts.push([x, y0 + Math.sin(x * 0.012 + b * 2) * 4 + (hash(x + b) - 0.5) * 3]);
|
|
605
|
+
pts.push([W, skyH + 8], [0, skyH + 8]);
|
|
606
|
+
fill(g, pts, P.bands[b]);
|
|
607
|
+
}
|
|
608
|
+
for (let i = 0; i < 16; i++) {
|
|
609
|
+
const y = skyH * (0.08 + 0.75 * hash(i * 31)), x = hash(i * 17) * W - 40, l = 40 + hash(i * 13) * 120;
|
|
610
|
+
cut(g, night ? '#3b4a85' : '#f6d38a', x, y, x + l, y + (hash(i) - 0.5) * 2, 2.6);
|
|
611
|
+
}
|
|
612
|
+
for (let k = 0; k < 3; k++) { // cloud banks: long and flat, cut out of the paper
|
|
613
|
+
const cx = W * (0.15 + 0.35 * k) + (hash(k * 9) - 0.5) * W * 0.1, cy = skyH * (0.2 + 0.18 * hash(k * 5 + 1)), cw = W * (0.14 + 0.08 * hash(k)), ch = Math.max(7, skyH * 0.06);
|
|
614
|
+
const cl = [];
|
|
615
|
+
for (let q = 0; q <= 16; q++) { const a = Math.PI + Math.PI * q / 16; cl.push([cx + Math.cos(a) * cw, cy + Math.sin(a) * ch * (1 + 0.5 * Math.sin(q * 1.7 + k))]); }
|
|
616
|
+
cl.push([cx + cw, cy + ch * 0.35], [cx - cw, cy + ch * 0.35]);
|
|
617
|
+
fill(g, cl, night ? '#2c3870' : '#f2c48a'); Art.ink(g, cl, 2.2, P.line, 40 + k);
|
|
618
|
+
cut(g, night ? '#3b4a85' : '#e9a75a', cx - cw * 0.6, cy + ch * 0.05, cx + cw * 0.3, cy, 2.2);
|
|
619
|
+
}
|
|
620
|
+
if (night) {
|
|
621
|
+
g.fillStyle = P.paper;
|
|
622
|
+
for (let i = 0; i < 40; i++) { g.beginPath(); g.arc(hash(i * 1.7) * W, hash(i * 3.1 + 1) * skyH * 0.7, 0.9 + hash(i * 5.3) * 1.4, 0, TAU); g.fill(); }
|
|
623
|
+
const mx = W * (L.tall ? 0.78 : 0.2), my = skyH * 0.5, mr = skyH * 0.15;
|
|
624
|
+
fill(g, ellipsePts(mx, my, mr, mr, 30, 77, 0.02), P.paper); fill(g, ellipsePts(mx + mr * 0.45, my - mr * 0.22, mr * 0.84, mr * 0.84, 30, 78, 0.02), P.bands[1]);
|
|
625
|
+
}
|
|
626
|
+
Art.speckle(g, 0, 0, W, skyH, 0.01, 5, 1.3);
|
|
627
|
+
return c;
|
|
628
|
+
}
|
|
629
|
+
// the sun runs along above the hedge, sinking slowly, and drops into it at the very end
|
|
630
|
+
function sunAt(L, p) {
|
|
631
|
+
const r = L.skyH * (L.tall ? 0.16 : 0.2), x = lerp(L.W * 0.12, L.W * 0.88, p), y0 = L.tall ? Math.max(L.skyH * 0.38, 66 + r) : L.skyH * 0.4;
|
|
632
|
+
const sink = clamp((p - 0.97) / 0.03, 0, 1), y1 = L.skyH - 34 - r * 0.4;
|
|
633
|
+
return {x, y: lerp(y0, y1, Math.pow(Math.min(p, 0.97) / 0.97, 1.5)) + sink * sink * (r * 2.6 + 34), r};
|
|
634
|
+
}
|
|
635
|
+
// beads on the road: one for every slice of the evening
|
|
636
|
+
function beads(L) { return L.W < 600 ? 9 : 12; }
|
|
637
|
+
function beadAt(L, q) { return sunAt(L, q / beads(L) * 0.97); }
|
|
638
|
+
// p: how far the sun has come; flash: beads re-inked by an apple or burnt by a sting (q -> {k, kind})
|
|
639
|
+
// The road is a string of big beads: ahead of the sun they are inked marigold, behind it they are
|
|
640
|
+
// empty sockets. Count the marigold ones and you know how much evening is left.
|
|
641
|
+
function sky(ctx, L, p, night, flash, count) {
|
|
642
|
+
each(night, (run, a) => { ctx.drawImage(run.sky, 0, 0, L.W, L.skyH + 8); });
|
|
643
|
+
ctx.globalAlpha = 1;
|
|
644
|
+
const s = sunAt(L, p), nb = beads(L), br = clamp(L.W / 70, 8, 15);
|
|
645
|
+
if (night < 1) {
|
|
646
|
+
ctx.globalAlpha = 1 - night;
|
|
647
|
+
const road = []; for (let q = 0; q <= 60; q++) { const a = sunAt(L, q / 60 * 0.97); road.push([a.x, a.y]); }
|
|
648
|
+
Art.ink(ctx, road, br * 0.5, Art.INKS.dusk.ink, 31, false);
|
|
649
|
+
for (let q = 0; q <= nb; q++) {
|
|
650
|
+
const pp = q / nb * 0.97, f = flash && flash[q], a = sunAt(L, pp), end = q === nb;
|
|
651
|
+
const lit = pp >= p - 0.003, k = f ? f.k : 1;
|
|
652
|
+
let R = br * (end ? 1.35 : 1);
|
|
653
|
+
ctx.fillStyle = Art.INKS.dusk.ink; ctx.beginPath(); ctx.arc(a.x, a.y, R + 2.6, 0, TAU); ctx.fill();
|
|
654
|
+
if (f && f.kind === 'burn') { // a sting: the bead flares white and burns out
|
|
655
|
+
const fl = 1 - k; ctx.fillStyle = mix('#fff4d0', Art.INKS.dusk.paper, fl); ctx.beginPath(); ctx.arc(a.x, a.y, R * (1 + Math.sin(fl * Math.PI) * 0.9), 0, TAU); ctx.fill();
|
|
656
|
+
ctx.fillStyle = Art.INKS.dusk.ink; ctx.beginPath(); ctx.arc(a.x, a.y, R * 0.45 * fl, 0, TAU); ctx.fill();
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (f && f.kind === 'gift') R *= 1 + Math.sin(clamp(1 - k, 0, 1) * Math.PI) * 0.6;
|
|
660
|
+
ctx.fillStyle = lit ? (end ? Art.INKS.dusk.paper : '#e07a3a') : Art.INKS.dusk.paper;
|
|
661
|
+
ctx.beginPath(); ctx.arc(a.x, a.y, R, 0, TAU); ctx.fill();
|
|
662
|
+
if (lit && end) { ctx.fillStyle = '#e07a3a'; ctx.beginPath(); ctx.arc(a.x, a.y, R * 0.55, 0, TAU); ctx.fill(); }
|
|
663
|
+
else if (lit) { ctx.fillStyle = '#f6cf6a'; ctx.beginPath(); ctx.arc(a.x - R * 0.3, a.y - R * 0.3, R * 0.3, 0, TAU); ctx.fill(); }
|
|
664
|
+
else { ctx.fillStyle = Art.INKS.dusk.ink; ctx.beginPath(); ctx.arc(a.x, a.y, R * 0.32, 0, TAU); ctx.fill(); }
|
|
665
|
+
}
|
|
666
|
+
fill(ctx, ellipsePts(s.x, s.y, s.r * 1.6, s.r * 1.6, 36, 903, 0.03), '#f6cf6a');
|
|
667
|
+
fill(ctx, ellipsePts(s.x, s.y, s.r * 1.3, s.r * 1.3, 36, 904, 0.03), '#e07a3a');
|
|
668
|
+
const disc = ellipsePts(s.x, s.y, s.r, s.r, 36, 901, 0.022);
|
|
669
|
+
fill(ctx, disc, Art.INKS.dusk.sun, Art.REG, 0); Art.ink(ctx, disc, Math.max(2, s.r * 0.08), Art.INKS.dusk.line, 902);
|
|
670
|
+
if (count > 0) { // the last seconds are printed on the sun's face, each one stamped in
|
|
671
|
+
const n = Math.ceil(count), k = n - count, sz = Math.max(26, s.r * 1.45) * (k < 0.12 ? lerp(1.5, 1, k / 0.12) : 1);
|
|
672
|
+
ctx.font = `900 ${Math.round(sz)}px Fraunces, Georgia, serif`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
673
|
+
ctx.fillStyle = Art.INKS.dusk.poppy; ctx.fillText(n, s.x, s.y + sz * 0.05);
|
|
674
|
+
}
|
|
675
|
+
ctx.globalAlpha = 1;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function ground(ctx, night) { each(night, (run, a) => { ctx.drawImage(run.ground, 0, 0, S.L.W, S.L.H); }); ctx.globalAlpha = 1; }
|
|
679
|
+
|
|
680
|
+
// ---- a burrow and what is in it
|
|
681
|
+
// clip to everything above the hole's near edge, so whatever is in it comes out of the ground
|
|
682
|
+
function clipHole(ctx, h) {
|
|
683
|
+
const {x, y} = h, hw = h.rx * 0.8, hr = h.ry * 0.7;
|
|
684
|
+
ctx.beginPath(); ctx.moveTo(x - h.r * 3, y); ctx.lineTo(x - h.r * 3, y - h.r * 7); ctx.lineTo(x + h.r * 3, y - h.r * 7); ctx.lineTo(x + h.r * 3, y); ctx.lineTo(x + hw, y);
|
|
685
|
+
ctx.ellipse(x, y, hw, hr, 0, 0, Math.PI); ctx.closePath(); ctx.clip();
|
|
686
|
+
}
|
|
687
|
+
// o: {kind 'hog'|'wasp', rise, squash, tuck, face, apple, look, sniff, variant, burst, t, flee}
|
|
688
|
+
// lift: the heap heaving (the warning); shake: its sideways judder
|
|
689
|
+
function hole(ctx, h, o, night, lift = 0, shake = 0) {
|
|
690
|
+
each(night, (run, a) => {
|
|
691
|
+
const hp = run.heaps[h.i];
|
|
692
|
+
if (lift > 0) {
|
|
693
|
+
ctx.save(); ctx.translate(h.x + shake, h.y); ctx.scale(1 + lift * 0.05, 1 + lift * 0.45); ctx.translate(-h.x, -h.y - lift * h.ry * 0.25);
|
|
694
|
+
put(ctx, hp, h.x, h.y); ctx.restore();
|
|
695
|
+
} else put(ctx, hp, h.x, h.y);
|
|
696
|
+
if (o && o.burst != null) burst(ctx, h, o.burst, run.P);
|
|
697
|
+
if (o) occupant(ctx, h, o, run, a);
|
|
698
|
+
put(ctx, run.fronts[h.i], h.x + shake * 0.4, h.y);
|
|
699
|
+
});
|
|
700
|
+
ctx.globalAlpha = 1;
|
|
701
|
+
}
|
|
702
|
+
// the boop's colour moment: one flat burst of rust behind the head, printed and gone
|
|
703
|
+
function burst(ctx, h, k, P) {
|
|
704
|
+
if (k >= 1) return;
|
|
705
|
+
const e = 1 - Math.pow(1 - Math.min(1, k * 2.4), 3), rr = h.r * (0.8 + e * 0.55), x = h.x, y = h.y - h.r * 1.15;
|
|
706
|
+
ctx.save(); ctx.beginPath(); ctx.rect(h.x - h.r * 4, h.y - h.r * 6, h.r * 8, h.r * 6 - h.ry * 0.5); ctx.clip();
|
|
707
|
+
ctx.globalAlpha *= k < 0.5 ? 1 : 1 - (k - 0.5) / 0.5;
|
|
708
|
+
const pts = spikePts(x, y, rr, rr * 0.86, 11, 0.72, 1, 13, 0, TAU, 0.2);
|
|
709
|
+
fill(ctx, pts, '#e07a3a', Art.REG, Art.REG); Art.ink(ctx, pts, 2.6, P.line, 77);
|
|
710
|
+
ctx.restore();
|
|
711
|
+
}
|
|
712
|
+
function occupant(ctx, h, o, run, a) {
|
|
713
|
+
const r = h.r, x = h.x, row = run.rows[h.row], P = run.P;
|
|
714
|
+
ctx.save(); clipHole(ctx, h);
|
|
715
|
+
if (o.kind === 'wasp') {
|
|
716
|
+
// it hovers and judders; the wings whirr between two positions
|
|
717
|
+
const fl = o.flee || 0, yOff = (1 - o.rise) * r * 2.6, t = o.t || 0, bz = Math.sin(t * 90) * r * 0.025;
|
|
718
|
+
if (fl > 0) { ctx.restore(); ctx.save(); ctx.globalAlpha = a * (fl < 0.6 ? 1 : (1 - fl) / 0.4); }
|
|
719
|
+
const hx = x + bz + fl * fl * r * 4 + Math.sin(fl * 30) * r * 0.25 * fl, hy = h.y + yOff - r * 1.6 + Math.sin(t * 7) * r * 0.05 - fl * r * 3.2, flap = Math.sin(t * 120) > 0 ? 1 : 0.55;
|
|
720
|
+
ctx.translate(hx, hy); ctx.scale(0.8, 0.8); ctx.rotate(fl * 0.6); ctx.translate(-hx, -hy);
|
|
721
|
+
for (const sd of [-1, 1]) { ctx.save(); ctx.translate(hx + sd * r * 0.28, hy + r * 0.52); ctx.scale(sd * 0.9, flap * 0.9); put(ctx, row.wing, 0, 0); ctx.restore(); }
|
|
722
|
+
put(ctx, row.wasp, hx, hy);
|
|
723
|
+
if (!fl) { // buzz marks: short zigzags that flicker either side
|
|
724
|
+
ctx.strokeStyle = P.line; ctx.lineWidth = Math.max(2, r * 0.07); ctx.lineJoin = 'round'; ctx.lineCap = 'round';
|
|
725
|
+
for (const sd of [-1, 1]) { const bx = hx + sd * r * 1.15, by0 = hy + r * 0.2 + ((t * 9 | 0) % 2) * r * 0.08; ctx.beginPath(); ctx.moveTo(bx, by0 - r * 0.3); ctx.lineTo(bx + sd * r * 0.12, by0 - r * 0.15); ctx.lineTo(bx, by0); ctx.lineTo(bx + sd * r * 0.12, by0 + r * 0.15); ctx.stroke(); }
|
|
726
|
+
}
|
|
727
|
+
} else {
|
|
728
|
+
const yOff = (1 - o.rise) * r * 2.4, sq = o.squash || 0, base = h.y + yOff, by = base - r * 1.2, tuck = o.tuck || 0;
|
|
729
|
+
ctx.translate(x, base); ctx.scale(1 + sq * 0.24, 1 - sq * 0.32); ctx.translate(-x, -base);
|
|
730
|
+
put(ctx, row.bodies[(o.variant || 0) % 3], x, by);
|
|
731
|
+
if (o.apple) { // carried high on the spines, rocking as it sniffs about
|
|
732
|
+
const ax = x + r * 0.42, ay = by - r * 0.86, w = Math.sin((o.t || 0) * 5) * 0.12;
|
|
733
|
+
ctx.save(); ctx.translate(ax, ay + r * 0.3); ctx.rotate(w); ctx.scale(1.2, 1.2); put(ctx, row.apple, 0, -r * 0.25); ctx.restore();
|
|
734
|
+
}
|
|
735
|
+
const fs = 1 - tuck;
|
|
736
|
+
if (fs > 0.02) {
|
|
737
|
+
const fy = by + r * 0.3 + tuck * r * 0.5;
|
|
738
|
+
ctx.save(); ctx.translate(x, fy); ctx.scale(fs, fs); ctx.translate(-x, -fy);
|
|
739
|
+
put(ctx, row.face, x, fy); Art.hogEyes(ctx, x, fy, r, P, o.face, o.look, o.sniff);
|
|
740
|
+
ctx.restore();
|
|
741
|
+
}
|
|
742
|
+
if (tuck > 0.02) { ctx.globalAlpha = a * Math.min(1, tuck * 1.6); put(ctx, row.tuck, x, by + r * 0.2); ctx.globalAlpha = a; }
|
|
743
|
+
}
|
|
744
|
+
ctx.restore();
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// ---- effects
|
|
748
|
+
// the warning, k 0..1: the rim cracks and clods of earth jump off the heap
|
|
749
|
+
function telegraph(ctx, h, k, night) {
|
|
750
|
+
const r = h.r, e = Math.sin(Math.min(1, k * 1.3) * Math.PI / 2), soil = pal(night, 'soil'), clod = pal(night, 'clod');
|
|
751
|
+
ctx.strokeStyle = inkOf(night); ctx.lineWidth = Math.max(2.2, r * 0.07); ctx.lineJoin = 'round'; ctx.lineCap = 'round';
|
|
752
|
+
for (const sd of [-1, 1]) {
|
|
753
|
+
let px = h.x + sd * h.rx * 0.3, py = h.y - h.ry * 1.45; ctx.beginPath(); ctx.moveTo(px, py);
|
|
754
|
+
for (let q = 1; q <= 3; q++) { px += sd * h.rx * 0.12 * e; py += (q % 2 ? 1 : -0.2) * h.ry * 0.35 * e; ctx.lineTo(px, py); }
|
|
755
|
+
ctx.stroke();
|
|
756
|
+
}
|
|
757
|
+
for (let i = 0; i < 6; i++) {
|
|
758
|
+
const a = Math.PI * (1.1 + 0.8 * i / 5), j = Math.abs(Math.sin(k * 9 + i * 1.9)) * e;
|
|
759
|
+
const cx = h.x + Math.cos(a) * h.rx * (0.65 + j * 0.25), cy = h.y - h.ry * 1.5 - j * r * 1.1, s = r * (0.13 + 0.05 * (i % 2));
|
|
760
|
+
const pts = ellipsePts(cx, cy, s, s * 0.8, 9, i * 7 + 3, 0.22);
|
|
761
|
+
fill(ctx, pts, i % 2 ? clod : soil); Art.ink(ctx, pts, 1.8, inkOf(night), i);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
// a thump on bare earth: a few clods, nothing more
|
|
765
|
+
function dud(ctx, h, k, night) {
|
|
766
|
+
const e = Math.sin(Math.min(1, k) * Math.PI);
|
|
767
|
+
for (let i = 0; i < 4; i++) {
|
|
768
|
+
const a = Math.PI * (1.2 + 0.6 * i / 3), cx = h.x + Math.cos(a) * h.rx * (0.3 + k * 0.4), cy = h.y - h.ry * 0.4 - e * h.r * 0.5, s = h.r * 0.1;
|
|
769
|
+
const pts = ellipsePts(cx, cy, s, s * 0.8, 8, i * 3 + 1, 0.2);
|
|
770
|
+
ctx.globalAlpha = 1 - k; fill(ctx, pts, pal(night, 'soil')); Art.ink(ctx, pts, 1.6, inkOf(night), i); ctx.globalAlpha = 1;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function ouch(ctx, x, y, r, k, night, cost) {
|
|
774
|
+
const e = 1 - Math.pow(1 - Math.min(1, k * 2.4), 3), a = k < 0.7 ? 1 : 1 - (k - 0.7) / 0.3;
|
|
775
|
+
ctx.save(); ctx.globalAlpha = a;
|
|
776
|
+
const pts = spikePts(x, y, r * e, r * e * 0.78, 10, 0.55, 1.2, 9);
|
|
777
|
+
fill(ctx, pts, Art.INKS.dusk.poppy, Art.REG, Art.REG); Art.ink(ctx, pts, 3, Art.INKS.dusk.ink, 3);
|
|
778
|
+
ctx.font = `italic 900 ${Math.round(r * 0.5 * e)}px Fraunces, Georgia, serif`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
779
|
+
ctx.fillStyle = Art.INKS.dusk.paper; ctx.fillText('ouch!', x, y - (cost ? r * 0.12 : -r * 0.04));
|
|
780
|
+
if (cost) { ctx.font = `900 ${Math.round(r * 0.42 * e)}px Fraunces, Georgia, serif`; ctx.fillStyle = Art.INKS.dusk.ink; ctx.fillText(cost, x, y + r * 0.32); }
|
|
781
|
+
ctx.restore();
|
|
782
|
+
}
|
|
783
|
+
// a score springs out on a little garden tag, beside the hedgehog that earned it
|
|
784
|
+
function pop(ctx, x, y, text, k, size, hot) {
|
|
785
|
+
const e = 1 - Math.pow(1 - Math.min(1, k * 3), 3), a = k < 0.65 ? 1 : 1 - (k - 0.65) / 0.35;
|
|
786
|
+
const s = k < 0.12 ? lerp(0.4, 1.15, k / 0.12) : lerp(1.15, 1, Math.min(1, (k - 0.12) / 0.2));
|
|
787
|
+
ctx.save(); ctx.globalAlpha = a; ctx.translate(x, y - e * size * 0.6); ctx.scale(s, s); ctx.rotate(-0.06);
|
|
788
|
+
ctx.font = `900 ${Math.round(size)}px Fraunces, Georgia, serif`;
|
|
789
|
+
const w = ctx.measureText(text).width + size * 0.8, hh = size * 1.25;
|
|
790
|
+
const tag = [[-w / 2, 0], [-w / 2 + hh * 0.36, -hh / 2], [w / 2, -hh / 2], [w / 2, hh / 2], [-w / 2 + hh * 0.36, hh / 2]];
|
|
791
|
+
fill(ctx, tag, hot ? '#f6cf6a' : Art.INKS.dusk.paper, 2, 2); Art.ink(ctx, tag, 3, Art.INKS.dusk.ink, 5);
|
|
792
|
+
ctx.fillStyle = Art.INKS.dusk.ink; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(text, size * 0.12, size * 0.05);
|
|
793
|
+
ctx.restore();
|
|
794
|
+
}
|
|
795
|
+
// an apple thrown up to the sun's road
|
|
796
|
+
function flyingApple(ctx, x, y, r, spin) {
|
|
797
|
+
const sp = S.runs.dusk.rows[2].apple;
|
|
798
|
+
ctx.save(); ctx.translate(x, y); ctx.rotate(spin); ctx.scale(r, r); put(ctx, sp, 0, 0); ctx.restore();
|
|
799
|
+
}
|
|
800
|
+
// fireflies: an inked dot and a cut halo, blinking, kept off the burrows
|
|
801
|
+
function fireflies(ctx, L, t, night) {
|
|
802
|
+
if (night <= 0) return;
|
|
803
|
+
for (let i = 0; i < 16; i++) {
|
|
804
|
+
const x = (hash(i * 3.3) * L.W + Math.sin(t * 0.35 + i) * 50 + L.W * 2) % L.W, y = L.skyH + 40 + hash(i * 7.7) * (L.H - L.skyH - 80) + Math.sin(t * 0.6 + i * 2) * 24;
|
|
805
|
+
if (L.holes.some(h => Math.abs(h.x - x) < h.rx * 1.3 && y > h.y - h.r * 2.6 && y < h.y + h.ry * 2)) continue;
|
|
806
|
+
const b = Math.max(0, Math.sin(t * 2.1 + i * 1.7)), a = night * b;
|
|
807
|
+
if (a < 0.05) continue;
|
|
808
|
+
ctx.globalAlpha = a; ctx.fillStyle = '#f2c96e';
|
|
809
|
+
ctx.beginPath(); ctx.arc(x, y, 2.4 + b, 0, TAU); ctx.fill();
|
|
810
|
+
ctx.globalAlpha = a * 0.3; ctx.beginPath(); ctx.arc(x + 1.5, y + 1.5, 6 + b * 3, 0, TAU); ctx.fill();
|
|
811
|
+
}
|
|
812
|
+
ctx.globalAlpha = 1;
|
|
813
|
+
}
|
|
814
|
+
// the printed hand that shows a newcomer what to do, tapping a nose
|
|
815
|
+
function hand(ctx, x, y, s, k) {
|
|
816
|
+
const press = Math.pow(Math.max(0, Math.sin(k * TAU)), 3), lift = (1 - press) * 10 * s;
|
|
817
|
+
ctx.save(); ctx.translate(x + lift * 0.6, y + lift); ctx.rotate(-0.55); ctx.scale(s, s);
|
|
818
|
+
// drawn with the fingertip at the origin
|
|
819
|
+
const finger = [[-5.5, 40], [-5.5, 4], [0, -1], [5.5, 4], [5.5, 34]];
|
|
820
|
+
const palm = [[-5.5, 38], [5.5, 30], [16, 34], [17, 46], [11, 62], [-9, 60], [-17, 44], [-13, 38]];
|
|
821
|
+
fill(ctx, palm, Art.INKS.dusk.paper, 1.5, 1.5); fill(ctx, finger, Art.INKS.dusk.paper, 1.5, 1.5);
|
|
822
|
+
Art.ink(ctx, finger, 2.6, Art.INKS.dusk.ink, 3, false);
|
|
823
|
+
Art.ink(ctx, [[5.5, 34], [16, 34], [17, 46], [11, 62], [-9, 60], [-17, 44], [-13, 38], [-5.5, 40]], 2.6, Art.INKS.dusk.ink, 4, false);
|
|
824
|
+
cut(ctx, Art.INKS.dusk.faceCut, -1.5, 10, -1, 26, 2.2);
|
|
825
|
+
ctx.restore();
|
|
826
|
+
if (press > 0.7) { ctx.strokeStyle = Art.INKS.dusk.ink; ctx.lineWidth = 2.4; ctx.lineCap = 'round'; for (const a of [-2.6, -1.9, -1.2]) { ctx.beginPath(); ctx.moveTo(x + Math.cos(a) * 12 * s, y + Math.sin(a) * 12 * s); ctx.lineTo(x + Math.cos(a) * 20 * s, y + Math.sin(a) * 20 * s); ctx.stroke(); } }
|
|
827
|
+
}
|
|
828
|
+
return {layout, build, bind, roller, sky, ground, hole, telegraph, dud, ouch, pop, flyingApple, fireflies, hand, sunAt, beadAt, beads, pal};
|
|
829
|
+
})();
|
|
830
|
+
// Prickle Patch - sound, all from Web Audio, played as one small garden band.
|
|
831
|
+
// A boop is a soft wooden mallet note. The streak walks a little tune in G pentatonic that loops
|
|
832
|
+
// inside one comfortable octave instead of climbing for ever, so a long run never gets shrill;
|
|
833
|
+
// a higher multiplier is heard as a fuller band (a bass note on the phrase, then a harmony, then a
|
|
834
|
+
// shaker), not as a higher pitch. Everything is panned to the burrow it came from, sits in a short
|
|
835
|
+
// garden-wall reverb, and is ducked when boops come thick and fast.
|
|
836
|
+
const Sound = (() => {
|
|
837
|
+
let ac = null, out = null, wet = null, muted = false, buzz = null, night = null, bed = null, birdT = 0, birdsOn = false;
|
|
838
|
+
const LEVEL = 0.7;
|
|
839
|
+
const hz = semis => 392 * Math.pow(2, semis / 12); // semitones from G4
|
|
840
|
+
// the streak's tune: 16 steps, G4 to E5, a phrase that rises, turns and comes home
|
|
841
|
+
const TUNE = [0, 4, 7, 9, 7, 4, 7, 12, 9, 7, 4, 2, 4, 7, 2, 0];
|
|
842
|
+
const BASS = [-12, -17, -15, -10]; // G3 D3 E3 A3, one per phrase quarter
|
|
843
|
+
function init() {
|
|
844
|
+
if (ac) { if (ac.state === 'suspended') ac.resume(); return; }
|
|
845
|
+
const C = window.AudioContext || window.webkitAudioContext; if (!C) return;
|
|
846
|
+
ac = new C();
|
|
847
|
+
out = ac.createGain(); out.gain.value = muted ? 0 : LEVEL;
|
|
848
|
+
const tone = ac.createBiquadFilter(); tone.type = 'highshelf'; tone.frequency.value = 5000; tone.gain.value = -6; // nothing glassy
|
|
849
|
+
const comp = ac.createDynamicsCompressor(); comp.threshold.value = -18; comp.ratio.value = 3; comp.attack.value = 0.004; comp.release.value = 0.2;
|
|
850
|
+
out.connect(tone); tone.connect(comp); comp.connect(ac.destination);
|
|
851
|
+
// a short, dark reverb: a garden with a brick wall, not a hall
|
|
852
|
+
const len = Math.floor(ac.sampleRate * 1.1), ir = ac.createBuffer(2, len, ac.sampleRate);
|
|
853
|
+
for (let c = 0; c < 2; c++) { const d = ir.getChannelData(c); for (let i = 0; i < len; i++) d[i] = (Math.random() * 2 - 1) * Math.pow(1 - i / len, 3.2); }
|
|
854
|
+
const conv = ac.createConvolver(); conv.buffer = ir;
|
|
855
|
+
const damp = ac.createBiquadFilter(); damp.type = 'lowpass'; damp.frequency.value = 2400;
|
|
856
|
+
wet = ac.createGain(); wet.gain.value = 0.22; wet.connect(damp); damp.connect(conv); conv.connect(out);
|
|
857
|
+
}
|
|
858
|
+
function setMuted(m) { muted = m; if (out) out.gain.setTargetAtTime(m ? 0 : LEVEL, ac.currentTime, 0.03); }
|
|
859
|
+
const now = () => ac.currentTime + 0.004;
|
|
860
|
+
const ok = () => ac && !muted;
|
|
861
|
+
// a channel panned to a place on the lawn (-1 left .. 1 right), with a little sent to the reverb
|
|
862
|
+
function bus(pan = 0, send = 1) {
|
|
863
|
+
const g = ac.createGain(), p = ac.createStereoPanner ? ac.createStereoPanner() : null;
|
|
864
|
+
if (p) { p.pan.value = Math.max(-1, Math.min(1, pan * 0.7)); g.connect(p); p.connect(out); if (send) p.connect(wet); }
|
|
865
|
+
else { g.connect(out); if (send) g.connect(wet); }
|
|
866
|
+
return g;
|
|
867
|
+
}
|
|
868
|
+
function env(g, t, a, peak, d) { g.gain.setValueAtTime(0.0001, t); g.gain.exponentialRampToValueAtTime(Math.max(0.0002, peak), t + a); g.gain.exponentialRampToValueAtTime(0.0001, t + a + d); }
|
|
869
|
+
function osc(type, f0, f1, t, a, peak, d, dest) {
|
|
870
|
+
const o = ac.createOscillator(), g = ac.createGain(); o.type = type;
|
|
871
|
+
o.frequency.setValueAtTime(f0, t); if (f1) o.frequency.exponentialRampToValueAtTime(f1, t + a + d);
|
|
872
|
+
env(g, t, a, peak, d); o.connect(g); g.connect(dest); o.start(t); o.stop(t + a + d + 0.05);
|
|
873
|
+
}
|
|
874
|
+
let noiseBuf = null;
|
|
875
|
+
function getNoise() { if (!noiseBuf) { noiseBuf = ac.createBuffer(1, ac.sampleRate, ac.sampleRate); const d = noiseBuf.getChannelData(0); for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1; } return noiseBuf; }
|
|
876
|
+
function noise(t, dur, peak, type, freq, q, dest, a = 0.003) {
|
|
877
|
+
const s = ac.createBufferSource(), f = ac.createBiquadFilter(), g = ac.createGain();
|
|
878
|
+
s.buffer = getNoise(); s.playbackRate.value = 0.9 + Math.random() * 0.2; f.type = type; f.frequency.value = freq; f.Q.value = q;
|
|
879
|
+
env(g, t, a, peak, dur); s.connect(f); f.connect(g); g.connect(dest); s.start(t, Math.random() * 0.5); s.stop(t + a + dur + 0.05);
|
|
880
|
+
}
|
|
881
|
+
// a mallet on a wooden bar: a round fundamental, a fourth partial that dies fast, a knock
|
|
882
|
+
function mallet(f, t, vel, dest, bright = 0) {
|
|
883
|
+
const d = 0.5 * Math.pow(440 / f, 0.35);
|
|
884
|
+
osc('sine', f * 1.004, f, t, 0.002, 0.34 * vel, d, dest);
|
|
885
|
+
osc('sine', f * 3.98, 0, t, 0.001, (0.05 + bright * 0.05) * vel, 0.05, dest);
|
|
886
|
+
osc('triangle', f * 2, 0, t, 0.002, 0.03 * vel, 0.09, dest);
|
|
887
|
+
noise(t, 0.012, 0.05 * vel, 'bandpass', Math.min(5000, f * 3), 2, dest);
|
|
888
|
+
}
|
|
889
|
+
let lastBoop = 0;
|
|
890
|
+
return {
|
|
891
|
+
init, setMuted, get muted() { return muted; },
|
|
892
|
+
// step: 0-based position in the streak; mult: the multiplier now; pan: where on the lawn
|
|
893
|
+
boop(step, quick, mult = 1, pan = 0) {
|
|
894
|
+
if (!ok()) return; const t = now();
|
|
895
|
+
const gap = t - lastBoop; lastBoop = t;
|
|
896
|
+
const vel = (0.85 + Math.random() * 0.15) * (gap < 0.09 ? 0.6 : gap < 0.2 ? 0.8 : 1);
|
|
897
|
+
const b = bus(pan), i = step % TUNE.length;
|
|
898
|
+
mallet(hz(TUNE[i]), t, vel, b, quick ? 1 : 0);
|
|
899
|
+
noise(t, 0.04, 0.05 * vel, 'lowpass', 900, 0.7, b); // the soft thump of a nose
|
|
900
|
+
if (mult >= 2 && i % 4 === 0) mallet(hz(BASS[(i / 4) | 0]), t, 0.55 * vel, bus(0));
|
|
901
|
+
if (mult >= 3 && i % 2 === 1) mallet(hz(TUNE[i] - (TUNE[i] % 12 >= 4 ? 3 : 5)), t + 0.012, 0.32 * vel, b);
|
|
902
|
+
if (mult >= 4) noise(t + 0.06, 0.05, 0.035, 'bandpass', 6500, 1.5, bus(-pan, 0)); // a shaker on the off-beat
|
|
903
|
+
},
|
|
904
|
+
// the multiplier goes up: a quick roll up the bars, ending on the home note an octave up
|
|
905
|
+
mult(m) { if (!ok()) return; const t = now(), b = bus(0); [0, 4, 7, 12].forEach((s, i) => mallet(hz(s), t + i * 0.06, i === 3 ? 0.7 : 0.45, b, 1)); },
|
|
906
|
+
sting(pan = 0) {
|
|
907
|
+
if (!ok()) return; const t = now(), b = bus(pan);
|
|
908
|
+
// a dry zip of wings, the smack, and a low sour pair
|
|
909
|
+
const o = ac.createOscillator(), f = ac.createBiquadFilter(), g = ac.createGain(), am = ac.createOscillator(), ag = ac.createGain();
|
|
910
|
+
o.type = 'sawtooth'; o.frequency.setValueAtTime(260, t); o.frequency.exponentialRampToValueAtTime(150, t + 0.2);
|
|
911
|
+
am.frequency.value = 38; ag.gain.value = 0.5; am.connect(ag); ag.connect(g.gain);
|
|
912
|
+
f.type = 'lowpass'; f.frequency.value = 1400; env(g, t, 0.005, 0.16, 0.2);
|
|
913
|
+
o.connect(f); f.connect(g); g.connect(b); o.start(t); am.start(t); o.stop(t + 0.3); am.stop(t + 0.3);
|
|
914
|
+
noise(t, 0.07, 0.3, 'lowpass', 1800, 0.8, b);
|
|
915
|
+
osc('sine', 150, 90, t, 0.003, 0.3, 0.16, b);
|
|
916
|
+
osc('triangle', hz(-11), 0, t + 0.05, 0.01, 0.09, 0.32, b); osc('triangle', hz(-10), 0, t + 0.05, 0.01, 0.07, 0.32, b);
|
|
917
|
+
},
|
|
918
|
+
// a hedgehog gets away: a soft huff and a falling two-note shrug
|
|
919
|
+
escape(pan = 0) { if (!ok()) return; const t = now(), b = bus(pan); noise(t, 0.16, 0.07, 'lowpass', 700, 0.6, b, 0.02); mallet(hz(-1), t + 0.02, 0.3, b); mallet(hz(-5), t + 0.13, 0.25, b); },
|
|
920
|
+
rise(kind, pan = 0) { if (!ok()) return; noise(now(), 0.12, 0.05, 'bandpass', 1100, 0.8, bus(pan, 0), 0.02); },
|
|
921
|
+
dud(pan = 0) { if (!ok()) return; const t = now(), b = bus(pan, 0); osc('sine', 110, 60, t, 0.003, 0.22, 0.1, b); noise(t, 0.06, 0.08, 'lowpass', 320, 0.7, b); },
|
|
922
|
+
// an apple: a crunch, then a little rising gift
|
|
923
|
+
apple(pan = 0) { if (!ok()) return; const t = now(), b = bus(pan); noise(t, 0.06, 0.18, 'bandpass', 2600, 1.2, b); noise(t + 0.03, 0.05, 0.12, 'bandpass', 1700, 1.2, b); [7, 12, 16].forEach((s, i) => mallet(hz(s), t + 0.14 + i * 0.07, 0.45, bus(0), 1)); },
|
|
924
|
+
// the last seconds: a woodblock, the final one lower
|
|
925
|
+
tick(last) { if (!ok()) return; const t = now(), b = bus(0, 0); osc('sine', last ? 640 : 900, 0, t, 0.001, 0.16, 0.05, b); noise(t, 0.018, 0.08, 'bandpass', last ? 1500 : 2100, 5, b); },
|
|
926
|
+
nightfall() {
|
|
927
|
+
if (!ok()) return; const t = now(), b = bus(0);
|
|
928
|
+
[12, 7, 4, 0, -5].forEach((s, i) => mallet(hz(s), t + i * 0.14, 0.4, b));
|
|
929
|
+
[-12, -5, 4].forEach(s => { const o = ac.createOscillator(), f = ac.createBiquadFilter(), g = ac.createGain(); o.type = 'triangle'; o.frequency.value = hz(s); f.type = 'lowpass'; f.frequency.value = 900;
|
|
930
|
+
g.gain.setValueAtTime(0.0001, t); g.gain.linearRampToValueAtTime(0.035, t + 0.6); g.gain.exponentialRampToValueAtTime(0.0001, t + 3); o.connect(f); f.connect(g); g.connect(b); o.start(t); o.stop(t + 3.1); });
|
|
931
|
+
},
|
|
932
|
+
// the buzz: two wing-beats a hair apart, dark and low, following the wasps across the lawn
|
|
933
|
+
wasps(n, pan = 0) {
|
|
934
|
+
if (!ac) return;
|
|
935
|
+
if (!buzz) {
|
|
936
|
+
const g = ac.createGain(), p = ac.createStereoPanner ? ac.createStereoPanner() : null, f = ac.createBiquadFilter(), am = ac.createGain();
|
|
937
|
+
f.type = 'lowpass'; f.frequency.value = 1000; f.Q.value = 0.7;
|
|
938
|
+
const wob = ac.createOscillator(), wg = ac.createGain(); wob.frequency.value = 5.5; wg.gain.value = 6; wob.connect(wg);
|
|
939
|
+
for (const fr of [186, 191.5]) { const o = ac.createOscillator(); o.type = 'sawtooth'; o.frequency.value = fr; wg.connect(o.frequency); o.connect(f); o.start(); }
|
|
940
|
+
const trem = ac.createOscillator(), tg = ac.createGain(); trem.frequency.value = 11; tg.gain.value = 0.25; trem.connect(tg); tg.connect(am.gain); am.gain.value = 0.75;
|
|
941
|
+
f.connect(am); am.connect(g); g.gain.value = 0;
|
|
942
|
+
if (p) { g.connect(p); p.connect(out); } else g.connect(out);
|
|
943
|
+
wob.start(); trem.start(); buzz = {g, p};
|
|
944
|
+
}
|
|
945
|
+
const t = ac.currentTime;
|
|
946
|
+
buzz.g.gain.setTargetAtTime(n > 0 ? Math.min(0.06, 0.035 + n * 0.012) : 0, t, n > 0 ? 0.05 : 0.08);
|
|
947
|
+
if (buzz.p) buzz.p.pan.setTargetAtTime(Math.max(-1, Math.min(1, pan * 0.7)), t, 0.1);
|
|
948
|
+
},
|
|
949
|
+
// the evening: a hush of air, and now and then a blackbird somewhere along the hedge
|
|
950
|
+
ambience(on) {
|
|
951
|
+
if (!ac) return;
|
|
952
|
+
if (!bed) {
|
|
953
|
+
const s = ac.createBufferSource(), f = ac.createBiquadFilter(), g = ac.createGain();
|
|
954
|
+
s.buffer = getNoise(); s.loop = true; f.type = 'lowpass'; f.frequency.value = 380; g.gain.value = 0;
|
|
955
|
+
s.connect(f); f.connect(g); g.connect(out); s.start(); bed = g;
|
|
956
|
+
}
|
|
957
|
+
bed.gain.setTargetAtTime(on && !muted ? 0.012 : 0, ac.currentTime, 0.6);
|
|
958
|
+
birdsOn = on; birdT = Math.min(birdT, ac.currentTime + 2);
|
|
959
|
+
},
|
|
960
|
+
// called every frame: sings the birds and the crickets when they are due
|
|
961
|
+
tick2() {
|
|
962
|
+
if (!ok()) return; const t = ac.currentTime;
|
|
963
|
+
if (birdsOn && t > birdT) {
|
|
964
|
+
birdT = t + 4 + Math.random() * 6;
|
|
965
|
+
const b = bus(Math.random() * 2 - 1), n = 3 + (Math.random() * 4 | 0), base = 1700 + Math.random() * 700;
|
|
966
|
+
for (let i = 0; i < n; i++) {
|
|
967
|
+
const s = t + 0.05 + i * (0.09 + Math.random() * 0.07), f0 = base * (0.8 + Math.random() * 0.6), f1 = f0 * (Math.random() < 0.5 ? 1.25 : 0.8);
|
|
968
|
+
osc('sine', f0, f1, s, 0.012, 0.022, 0.06 + Math.random() * 0.06, b);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
if (night && t > night.at) { // crickets: little trains of chirps, not a steady whine
|
|
972
|
+
night.at = t + 0.5 + Math.random() * 0.9; const b = bus(Math.random() * 1.6 - 0.8, 0), f = 4200 + Math.random() * 500;
|
|
973
|
+
for (let i = 0; i < 3 + (Math.random() * 3 | 0); i++) osc('sine', f, 0, t + i * 0.045, 0.004, 0.012, 0.025, b);
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
crickets(on) { if (!ac) return; night = on ? (night || {at: ac.currentTime + 0.4}) : null; }
|
|
977
|
+
};
|
|
978
|
+
})();
|
|
979
|
+
// Prickle Patch - the page: the loop, touch and keys, the tags, and the screens between rounds.
|
|
980
|
+
(() => {
|
|
981
|
+
const C = PrickleCore, {lerp, clamp, hash} = Art;
|
|
982
|
+
const $ = id => document.getElementById(id);
|
|
983
|
+
const cv = $('cv'), ctx = cv.getContext('2d');
|
|
984
|
+
const RM = matchMedia('(prefers-reduced-motion: reduce)');
|
|
985
|
+
const KEY = 'pricklePatch';
|
|
986
|
+
const store = (() => { try { return JSON.parse(localStorage.getItem(KEY)) || {}; } catch (e) { return {}; } })();
|
|
987
|
+
store.best = store.best || 0; store.bestStreak = store.bestStreak || 0; store.rounds = store.rounds || 0;
|
|
988
|
+
// the old Whac-a-Hedgehog kept one number, its best, at 1-5 points a hit. A boop here is worth
|
|
989
|
+
// about a hundred times that, so the old best comes across at that rate (and is kept as it was).
|
|
990
|
+
try {
|
|
991
|
+
const old = parseInt(localStorage.getItem('whacHighScore'), 10);
|
|
992
|
+
if (old > 0 && store.legacy == null) { store.legacy = old; store.best = Math.max(store.best, old * 100); localStorage.setItem(KEY, JSON.stringify(store)); }
|
|
993
|
+
} catch (e) {}
|
|
994
|
+
const save = () => { try { localStorage.setItem(KEY, JSON.stringify(store)); } catch (e) {} };
|
|
995
|
+
if (store.muted) Sound.setMuted(true);
|
|
996
|
+
|
|
997
|
+
let L = null, dpr = 1, mode = 'title', modeAt = 0, clock = 0, last = 0;
|
|
998
|
+
let core = null, night = 0, pShown = 0, flashes = {}, fx = [], shakeAt = -9, shakeMag = 0;
|
|
999
|
+
let titleHog = null, curtain = [], ready = false, resultsAt = 0;
|
|
1000
|
+
const easeOutBack = k => { const c = 1.6; k -= 1; return 1 + (c + 1) * k * k * k + c * k * k; };
|
|
1001
|
+
const easeIn = k => k * k * k;
|
|
1002
|
+
const easeOut = k => 1 - Math.pow(1 - k, 3);
|
|
1003
|
+
const fmt = n => Math.round(n).toLocaleString('en-US');
|
|
1004
|
+
|
|
1005
|
+
// ------------------------------------------------------------------ layout
|
|
1006
|
+
function resize() {
|
|
1007
|
+
const W = innerWidth, H = innerHeight;
|
|
1008
|
+
dpr = Math.min(2, devicePixelRatio || 1);
|
|
1009
|
+
cv.width = Math.round(W * dpr); cv.height = Math.round(H * dpr);
|
|
1010
|
+
L = Scene.layout(W, H); Scene.build(L, dpr); Scene.bind(ctx);
|
|
1011
|
+
document.documentElement.style.setProperty('--sky', L.skyH + 'px');
|
|
1012
|
+
document.documentElement.style.setProperty('--side', Math.max(0, (W - L.bw) / 2 - 20) + 'px');
|
|
1013
|
+
document.body.classList.toggle('tall', L.tall);
|
|
1014
|
+
}
|
|
1015
|
+
let rT = 0; addEventListener('resize', () => { clearTimeout(rT); rT = setTimeout(resize, 120); });
|
|
1016
|
+
|
|
1017
|
+
// ------------------------------------------------------------------ the tags
|
|
1018
|
+
const scoreEl = $('score'), multEl = $('mult'), pipsEl = $('pips'), streakTag = $('streakTag'), scoreTag = $('scoreTag');
|
|
1019
|
+
let scoreShown = 0, scoreTo = 0;
|
|
1020
|
+
function flowerSVG() {
|
|
1021
|
+
let d = '';
|
|
1022
|
+
for (let k = 0; k < 8; k++) { const a = k / 8 * Math.PI * 2, cx = (12 + Math.cos(a) * 6.5).toFixed(1), cy = (12 + Math.sin(a) * 6.5).toFixed(1); d += `<ellipse cx="${cx}" cy="${cy}" rx="4.2" ry="3" transform="rotate(${k * 45} ${cx} ${cy})"/>`; }
|
|
1023
|
+
return `<svg viewBox="0 0 24 24" aria-hidden="true"><g class="petals" stroke="#1d1813" stroke-width="1.8">${d}</g><circle class="heart" cx="12" cy="12" r="3.6" stroke="#1d1813" stroke-width="1.8"/></svg>`;
|
|
1024
|
+
}
|
|
1025
|
+
for (let i = 0; i < C.PIPS; i++) { const s = document.createElement('i'); s.innerHTML = flowerSVG(); pipsEl.appendChild(s); }
|
|
1026
|
+
const pipEls = [...pipsEl.children];
|
|
1027
|
+
function showStreak(bump) {
|
|
1028
|
+
const m = core ? core.mult : 1, p = core ? (core.mult >= C.MAX_MULT ? C.PIPS : core.pips) : 0;
|
|
1029
|
+
multEl.textContent = '×' + m;
|
|
1030
|
+
pipEls.forEach((el, i) => { const was = el.classList.contains('on'); el.classList.toggle('on', i < p); if (!was && i < p) { el.classList.remove('hop'); void el.offsetWidth; el.classList.add('hop'); } });
|
|
1031
|
+
if (bump) { streakTag.classList.remove('bump'); void streakTag.offsetWidth; streakTag.classList.add('bump'); }
|
|
1032
|
+
streakTag.classList.toggle('max', m >= C.MAX_MULT);
|
|
1033
|
+
}
|
|
1034
|
+
// the streak is lost where it was lost: wilted petals drop off the burrow and drift down
|
|
1035
|
+
function scatter(n, h) {
|
|
1036
|
+
const x0 = h ? h.x : innerWidth / 2, y0 = h ? h.y - h.r * 1.4 : innerHeight / 2;
|
|
1037
|
+
for (let i = 0; i < Math.min(16, 4 + n * 2); i++) fx.push({type: 'petal', t0: clock, x: x0 + (Math.random() - 0.5) * 20, y: y0,
|
|
1038
|
+
vx: (Math.random() - 0.5) * 160, vy: -40 - Math.random() * 60, spin: (Math.random() - 0.5) * 6, s: 0.9 + Math.random() * 0.7});
|
|
1039
|
+
}
|
|
1040
|
+
function pipXY(i) { const r = pipEls[Math.max(0, Math.min(C.PIPS - 1, i))].getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; }
|
|
1041
|
+
function emptyPips() { streakTag.classList.remove('lose'); void streakTag.offsetWidth; streakTag.classList.add('lose'); }
|
|
1042
|
+
|
|
1043
|
+
// ------------------------------------------------------------------ screens
|
|
1044
|
+
const titleEl = $('title'), resultsEl = $('results'), pauseEl = $('pause'), hud = $('hud');
|
|
1045
|
+
function setMode(m) {
|
|
1046
|
+
mode = m; modeAt = clock;
|
|
1047
|
+
document.body.dataset.mode = m;
|
|
1048
|
+
titleEl.hidden = m !== 'title';
|
|
1049
|
+
resultsEl.classList.toggle('show', m === 'results');
|
|
1050
|
+
pauseEl.hidden = m !== 'paused';
|
|
1051
|
+
if (m !== 'play' && m !== 'paused') Sound.wasps(0);
|
|
1052
|
+
Sound.crickets(m === 'results' || m === 'night');
|
|
1053
|
+
Sound.ambience(m === 'play' || m === 'title');
|
|
1054
|
+
}
|
|
1055
|
+
function showTitle() {
|
|
1056
|
+
const best = $('titleBest');
|
|
1057
|
+
if (store.best > 0) { best.hidden = false; $('titleBestN').textContent = fmt(store.best); $('titleRank').textContent = C.rank(store.best); }
|
|
1058
|
+
else best.hidden = true;
|
|
1059
|
+
titleHog = {phase: 'rise', t0: clock};
|
|
1060
|
+
night = 0; pShown = 0; core = null; curtain = []; fx = []; flashes = {};
|
|
1061
|
+
setMode('title');
|
|
1062
|
+
}
|
|
1063
|
+
function start() {
|
|
1064
|
+
Sound.init();
|
|
1065
|
+
core = C.create({seed: (Date.now() ^ (Math.random() * 1e9)) >>> 0, tutorial: store.rounds === 0});
|
|
1066
|
+
fx = []; flashes = {}; night = 0; pShown = 0; scoreShown = scoreTo = 0; scoreEl.textContent = '0';
|
|
1067
|
+
curtain = []; showStreak(false);
|
|
1068
|
+
setMode('play');
|
|
1069
|
+
}
|
|
1070
|
+
function finish() {
|
|
1071
|
+
store.rounds++;
|
|
1072
|
+
const isBest = core.score > store.best;
|
|
1073
|
+
if (isBest) store.best = core.score;
|
|
1074
|
+
store.bestStreak = Math.max(store.bestStreak, core.bestStreak);
|
|
1075
|
+
save();
|
|
1076
|
+
$('resScore').textContent = fmt(core.score);
|
|
1077
|
+
$('resStamp').hidden = !isBest || core.score === 0;
|
|
1078
|
+
$('resRank').textContent = C.rank(core.score);
|
|
1079
|
+
const nx = C.nextRank(core.score);
|
|
1080
|
+
$('resNext').textContent = nx ? `${fmt(nx[0] - core.score)} more for ${nx[1]}` : 'There is no one better at this.';
|
|
1081
|
+
$('resBest').textContent = isBest ? '' : `Best ${fmt(store.best)}`;
|
|
1082
|
+
$('resBoops').textContent = core.boops; $('resStreak').textContent = core.bestStreak; $('resStings').textContent = core.stings;
|
|
1083
|
+
// the hedgehogs come up to see how you did
|
|
1084
|
+
resultsEl.classList.add('show'); const R = resultsEl.getBoundingClientRect(); resultsEl.classList.remove('show');
|
|
1085
|
+
const clear = L.holes.filter(h => h.x + h.rx < R.left - 4 || h.x - h.rx > R.right + 4 || h.y - h.r * 2.6 > R.bottom + 30 || h.y + h.ry < R.top - 40).map(h => h.i);
|
|
1086
|
+
const holes = clear.sort((a, b) => hash(a * 13 + core.seed) - hash(b * 13 + core.seed)).slice(0, 3);
|
|
1087
|
+
curtain = holes.map((h, k) => ({hole: h, t0: clock + 0.3 + k * 0.22, id: 100 + h}));
|
|
1088
|
+
resultsAt = clock;
|
|
1089
|
+
setMode('results');
|
|
1090
|
+
setTimeout(() => $('again').focus({preventScroll: true}), 50);
|
|
1091
|
+
}
|
|
1092
|
+
function pause() { if (mode === 'play') setMode('paused'); }
|
|
1093
|
+
function resume() { if (mode === 'paused') { setMode('play'); last = performance.now(); } }
|
|
1094
|
+
document.addEventListener('visibilitychange', () => { if (document.hidden) pause(); });
|
|
1095
|
+
addEventListener('blur', pause);
|
|
1096
|
+
|
|
1097
|
+
// ------------------------------------------------------------------ input
|
|
1098
|
+
// where rows overlap, a touch could mean two burrows: one with a hedgehog up beats an empty one,
|
|
1099
|
+
// and anything beats a wasp, so a reach for a face never lands on the sting behind it
|
|
1100
|
+
function holeAt(x, y) {
|
|
1101
|
+
let best = -1, bs = -1e9;
|
|
1102
|
+
for (const h of L.holes) {
|
|
1103
|
+
const dx = (x - h.x) / (h.rx * 1.05), dy = (y - (h.y - h.r * 1.05)) / (h.r * 1.75), d = dx * dx + dy * dy;
|
|
1104
|
+
if (d >= 1.15) continue;
|
|
1105
|
+
const e = core && core.holes[h.i], live = e && (e.phase === 'rise' || e.phase === 'up' || e.phase === 'tuck');
|
|
1106
|
+
const score = -d + (live ? (e.kind === 'hog' ? 2 : -0.6) : 0);
|
|
1107
|
+
if (score > bs) { bs = score; best = h.i; }
|
|
1108
|
+
}
|
|
1109
|
+
return best;
|
|
1110
|
+
}
|
|
1111
|
+
function tapHole(i) {
|
|
1112
|
+
if (mode === 'title') {
|
|
1113
|
+
if (i === 4 && titleHog && titleHog.phase !== 'drop') {
|
|
1114
|
+
Sound.init(); Sound.boop(0, true);
|
|
1115
|
+
titleHog = {phase: 'drop', t0: clock};
|
|
1116
|
+
fx.push({type: 'burst', hole: 4, t0: clock});
|
|
1117
|
+
setTimeout(() => { if (mode === 'title') start(); }, 200);
|
|
1118
|
+
} else if (i >= 0) fx.push({type: 'dud', hole: i, t0: clock});
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
if (mode !== 'play' || i < 0) return;
|
|
1122
|
+
const before = core.streak; handle(C.tap(core, i), before);
|
|
1123
|
+
}
|
|
1124
|
+
addEventListener('pointerdown', e => {
|
|
1125
|
+
if (!ready) return;
|
|
1126
|
+
if (e.target.closest('button, a')) return;
|
|
1127
|
+
if (mode === 'paused') { resume(); return; }
|
|
1128
|
+
if (mode === 'results') return;
|
|
1129
|
+
e.preventDefault();
|
|
1130
|
+
tapHole(holeAt(e.clientX, e.clientY));
|
|
1131
|
+
}, {passive: false});
|
|
1132
|
+
const KEYMAP = {Numpad7: 0, Numpad8: 1, Numpad9: 2, Numpad4: 3, Numpad5: 4, Numpad6: 5, Numpad1: 6, Numpad2: 7, Numpad3: 8,
|
|
1133
|
+
KeyQ: 0, KeyW: 1, KeyE: 2, KeyA: 3, KeyS: 4, KeyD: 5, KeyZ: 6, KeyX: 7, KeyC: 8};
|
|
1134
|
+
addEventListener('keydown', e => {
|
|
1135
|
+
if (!ready || e.repeat) return;
|
|
1136
|
+
if (e.code === 'KeyM') { toggleMute(); return; }
|
|
1137
|
+
if (mode === 'paused') { if (e.code !== 'Tab') { resume(); e.preventDefault(); } return; }
|
|
1138
|
+
if ((e.code === 'Escape' || e.code === 'KeyP') && mode === 'play') { pause(); return; }
|
|
1139
|
+
if (e.code === 'Space' || e.code === 'Enter') {
|
|
1140
|
+
if (mode === 'title') { e.preventDefault(); tapHole(4); return; }
|
|
1141
|
+
if (mode === 'results' && clock - resultsAt > 0.8) { e.preventDefault(); start(); return; }
|
|
1142
|
+
}
|
|
1143
|
+
if (e.code in KEYMAP) { e.preventDefault(); tapHole(KEYMAP[e.code]); }
|
|
1144
|
+
});
|
|
1145
|
+
$('again').addEventListener('click', () => { if (clock - resultsAt > 0.8) start(); });
|
|
1146
|
+
function toggleMute() { Sound.init(); Sound.setMuted(!Sound.muted); store.muted = Sound.muted; save(); $('mute').classList.toggle('off', Sound.muted); $('mute').setAttribute('aria-label', Sound.muted ? 'Sound on' : 'Sound off'); }
|
|
1147
|
+
$('mute').addEventListener('click', toggleMute);
|
|
1148
|
+
$('mute').classList.toggle('off', Sound.muted);
|
|
1149
|
+
|
|
1150
|
+
// ------------------------------------------------------------------ what happened
|
|
1151
|
+
function beadFlash(p0, p1, kind) { // beads between two points of the evening light up or burn off
|
|
1152
|
+
const nb = Scene.beads(L), lo = Math.min(p0, p1), hi = Math.max(p0, p1);
|
|
1153
|
+
for (let q = 1; q <= nb; q++) { const pp = q / nb * 0.97; if (pp > lo && pp <= hi + 1e-6) flashes[q] = {t0: clock + (kind === 'gift' ? 0.45 : 0), kind}; }
|
|
1154
|
+
}
|
|
1155
|
+
// before: the streak as it stood before these events, so a break knows what it broke
|
|
1156
|
+
let lastHole = 4;
|
|
1157
|
+
const panOf = h => h ? h.x / L.W * 2 - 1 : 0;
|
|
1158
|
+
function handle(ev, before = 0) {
|
|
1159
|
+
const lostStreak = before;
|
|
1160
|
+
for (const e of ev) {
|
|
1161
|
+
const h = e.hole != null ? L.holes[e.hole] : null; if (e.hole != null) lastHole = e.hole;
|
|
1162
|
+
switch (e.type) {
|
|
1163
|
+
case 'rise': Sound.rise(e.kind, panOf(h)); break;
|
|
1164
|
+
case 'boop':
|
|
1165
|
+
Sound.boop(e.streak - 1, e.quick >= 40, core.mult, panOf(h));
|
|
1166
|
+
fx.push({type: 'pop', hole: e.hole, t0: clock, text: '+' + e.pts, hot: e.quick >= 40});
|
|
1167
|
+
scoreTo = core.score; showStreak(false);
|
|
1168
|
+
if (core.mult < C.MAX_MULT || e.mult < C.MAX_MULT) fx.push({type: 'pip', hole: e.hole, t0: clock, to: core.pips === 0 ? C.PIPS - 1 : core.pips - 1});
|
|
1169
|
+
if (navigator.vibrate) try { navigator.vibrate(8); } catch (x) {}
|
|
1170
|
+
break;
|
|
1171
|
+
case 'mult': Sound.mult(e.mult); showStreak(true); fx.push({type: 'stamp', hole: lastHole, t0: clock, text: '×' + e.mult}); break;
|
|
1172
|
+
case 'apple': {
|
|
1173
|
+
Sound.apple(panOf(h));
|
|
1174
|
+
const p0 = 1 - (core.left - e.gift) / C.ROUND, p1 = 1 - core.left / C.ROUND;
|
|
1175
|
+
beadFlash(p0, p1, 'gift');
|
|
1176
|
+
fx.push({type: 'apple', hole: e.hole, t0: clock, to: Scene.sunAt(L, Math.max(0, p1))});
|
|
1177
|
+
fx.push({type: 'time', t0: clock + 0.45, text: '+' + Math.round(e.gift) + 's', hot: true});
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
case 'escape': Sound.escape(panOf(h)); if (lostStreak >= 3) scatter(lostStreak, h); showStreak(false); emptyPips(); break;
|
|
1181
|
+
case 'sting': {
|
|
1182
|
+
Sound.sting(panOf(h));
|
|
1183
|
+
fx.push({type: 'ouch', hole: e.hole, t0: clock, cost: e.cost});
|
|
1184
|
+
if (!RM.matches) { shakeAt = clock; shakeMag = 9; }
|
|
1185
|
+
const p1 = 1 - core.left / C.ROUND; beadFlash(p1 - e.cost / C.ROUND, p1, 'burn');
|
|
1186
|
+
if (lostStreak >= 3) scatter(lostStreak, h); showStreak(false); emptyPips();
|
|
1187
|
+
if (navigator.vibrate) try { navigator.vibrate([40, 30, 40]); } catch (x) {}
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
case 'dud': Sound.dud(panOf(h)); fx.push({type: 'dud', hole: e.hole, t0: clock}); if (e.lost > 0) { showStreak(false); emptyPips(); } break;
|
|
1191
|
+
case 'end': Sound.nightfall(); setMode('night'); break;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// ------------------------------------------------------------------ drawing
|
|
1197
|
+
function hogVis(e, t, reduced) {
|
|
1198
|
+
const age = t - e.t0, base = {kind: e.kind, apple: e.apple, variant: e.id % 3, face: 'idle', t};
|
|
1199
|
+
const blink = ((t * 0.7 + e.id * 0.37) % 3.1) < 0.12;
|
|
1200
|
+
base.look = Math.sin(t * 1.3 + e.id) * 0.8; base.sniff = Math.sin(t * 13 + e.id) > 0.3 ? 1 : 0;
|
|
1201
|
+
if (blink) base.face = 'blink';
|
|
1202
|
+
switch (e.phase) {
|
|
1203
|
+
case 'warn': return null;
|
|
1204
|
+
case 'rise': { const k = clamp(age / C.RISE, 0, 1); base.rise = reduced ? easeOut(k) : easeOutBack(k); return base; }
|
|
1205
|
+
case 'up': base.rise = 1; return base;
|
|
1206
|
+
case 'tuck': base.rise = 1; base.tuck = easeOut(clamp(age / C.TUCK, 0, 1)); return base;
|
|
1207
|
+
case 'sink': base.rise = 1 - easeIn(clamp(age / C.SINK, 0, 1)); if (e.tucked) base.tuck = 1; return base;
|
|
1208
|
+
case 'drop': {
|
|
1209
|
+
base.face = 'boop'; base.apple = false;
|
|
1210
|
+
base.squash = reduced ? 0.5 * (1 - clamp(age / 0.2, 0, 1)) : Math.max(0, 1 - age / 0.16);
|
|
1211
|
+
base.rise = 1 - easeIn(clamp((age - 0.07) / 0.19, 0, 1));
|
|
1212
|
+
base.burst = age / 0.32; return base;
|
|
1213
|
+
}
|
|
1214
|
+
case 'flee': base.rise = 1; base.flee = clamp(age / C.FLEE, 0, 1); return base;
|
|
1215
|
+
}
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
function draw() {
|
|
1219
|
+
const W = L.W, H = L.H, reduced = RM.matches;
|
|
1220
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
1221
|
+
const sa = clock - shakeAt, sm = sa < 0.4 ? shakeMag * Math.exp(-sa * 9) * Math.sin(sa * 70) : 0;
|
|
1222
|
+
if (sm) ctx.translate(sm, sm * 0.4);
|
|
1223
|
+
// the sun's place: eased, so a sting or an apple moves it, not teleports it
|
|
1224
|
+
const pTrue = core ? 1 - core.left / C.ROUND : 0;
|
|
1225
|
+
pShown += (pTrue - pShown) * Math.min(1, (Math.abs(pTrue - pShown) > 0.01 ? 0.12 : 1));
|
|
1226
|
+
for (const q in flashes) { const f = flashes[q]; f.k = clamp(1 - (clock - f.t0) / 0.7, 0, 1); if (clock - f.t0 > 0.7) delete flashes[q]; else if (clock < f.t0) f.k = 1; }
|
|
1227
|
+
Scene.sky(ctx, L, mode === 'title' ? 0 : pShown, night, flashes, mode === 'play' && core.left <= 5 && core.left > 0 ? core.left : 0);
|
|
1228
|
+
Scene.ground(ctx, night);
|
|
1229
|
+
const t = core ? core.t : clock;
|
|
1230
|
+
for (const h of L.holes) {
|
|
1231
|
+
let o = null, lift = 0, shake = 0;
|
|
1232
|
+
const e = core && core.holes[h.i];
|
|
1233
|
+
if (e) {
|
|
1234
|
+
if (e.phase === 'warn') { const k = clamp((core.t - e.t0) / e.warn, 0, 1); lift = Math.sin(k * Math.PI * 0.5) * 0.9; shake = reduced ? 0 : Math.sin(core.t * 70 + h.i) * h.r * 0.05 * k; }
|
|
1235
|
+
o = hogVis(e, core.t, reduced);
|
|
1236
|
+
}
|
|
1237
|
+
if (mode === 'title' && h.i === 4 && titleHog) o = hogVis({...titleHog, kind: 'hog', id: 7, warn: 0}, clock, reduced);
|
|
1238
|
+
if ((mode === 'results' || mode === 'night') && !e) for (const c of curtain) if (c.hole === h.i && clock > c.t0) {
|
|
1239
|
+
const k = clamp((clock - c.t0) / C.RISE, 0, 1);
|
|
1240
|
+
o = hogVis({phase: k < 1 ? 'rise' : 'up', t0: c.t0, kind: 'hog', id: c.id}, clock, reduced);
|
|
1241
|
+
}
|
|
1242
|
+
if (o && !o.burst) { const b = fx.find(f => f.type === 'burst' && f.hole === h.i && clock - f.t0 < 0.35); if (b) o.burst = (clock - b.t0) / 0.32; }
|
|
1243
|
+
Scene.hole(ctx, h, o, night, lift, shake);
|
|
1244
|
+
if (lift > 0 && e) Scene.telegraph(ctx, h, clamp((core.t - e.t0) / e.warn, 0, 1), night);
|
|
1245
|
+
}
|
|
1246
|
+
// effects
|
|
1247
|
+
for (let i = fx.length - 1; i >= 0; i--) {
|
|
1248
|
+
const f = fx[i], age = clock - f.t0, h = f.hole != null ? L.holes[f.hole] : null;
|
|
1249
|
+
if (f.type === 'pop') { if (age < 0) continue; const k = age / 0.5; if (k >= 1) { fx.splice(i, 1); continue; } Scene.pop(ctx, h.x + h.r * 1.05 * (h.col === 2 ? -1 : 1), h.y - h.r * 2.05, f.text, k, Math.max(21, h.r * 0.52), f.hot); }
|
|
1250
|
+
else if (f.type === 'ouch') { const k = age / 0.55; if (k >= 1) { fx.splice(i, 1); continue; } Scene.ouch(ctx, h.x, h.y - h.r * 1.5, h.r * 1.25, k, night, '−' + f.cost + 's'); }
|
|
1251
|
+
else if (f.type === 'dud') { const k = age / 0.3; if (k >= 1) { fx.splice(i, 1); continue; } Scene.dud(ctx, h, k, night); }
|
|
1252
|
+
else if (f.type === 'apple') {
|
|
1253
|
+
const k = age / 0.5; if (k >= 1) { fx.splice(i, 1); continue; }
|
|
1254
|
+
const x0 = h.x + h.r * 0.5, y0 = h.y - h.r * 1.9, e = easeOut(k), x = lerp(x0, f.to.x, e), y = lerp(y0, f.to.y, e) - Math.sin(k * Math.PI) * h.r * 1.5;
|
|
1255
|
+
Scene.flyingApple(ctx, x, y, lerp(1, 0.6, k), k * 6);
|
|
1256
|
+
}
|
|
1257
|
+
else if (f.type === 'burst' && age > 0.4) fx.splice(i, 1);
|
|
1258
|
+
else if (f.type === 'pip') { // a marigold flies from the boop to its pip on the tag
|
|
1259
|
+
const k = age / 0.42; if (k >= 1) { fx.splice(i, 1); continue; }
|
|
1260
|
+
const [tx, ty] = pipXY(f.to), e = easeIn(k), x0 = h.x, y0 = h.y - h.r * 1.4;
|
|
1261
|
+
const x = lerp(x0, tx, e), y = lerp(y0, ty, e) - Math.sin(k * Math.PI) * h.r * 1.2;
|
|
1262
|
+
ctx.save(); ctx.translate(x, y); ctx.rotate(k * 5); const sc = lerp(1.3, 0.8, k);
|
|
1263
|
+
for (let q = 0; q < 8; q++) { const a = q / 8 * Math.PI * 2, pts = Art.ellipsePts(Math.cos(a) * 6 * sc, Math.sin(a) * 6 * sc, 4 * sc, 2.8 * sc, 8, q, 0); Art.fill(ctx, pts, '#e07a3a'); }
|
|
1264
|
+
ctx.fillStyle = '#8a3a22'; ctx.beginPath(); ctx.arc(0, 0, 3.2 * sc, 0, 7); ctx.fill();
|
|
1265
|
+
ctx.restore();
|
|
1266
|
+
}
|
|
1267
|
+
else if (f.type === 'stamp') { // the multiplier goes up: a big rubber stamp over the burrow that earned it
|
|
1268
|
+
const k = age / 0.55; if (k >= 1) { fx.splice(i, 1); continue; }
|
|
1269
|
+
const sz = Math.max(40, h.r * 1.1), s = k < 0.14 ? lerp(2.2, 0.92, easeOut(k / 0.14)) : k < 0.24 ? lerp(0.92, 1, (k - 0.14) / 0.1) : 1;
|
|
1270
|
+
ctx.save(); ctx.globalAlpha = k < 0.6 ? 1 : 1 - (k - 0.6) / 0.4; ctx.translate(clamp(h.x, sz * 1.3, W - sz * 1.3), h.y - h.r * 2.3 - (k > 0.5 ? (k - 0.5) * h.r * 1.4 : 0)); ctx.rotate(-0.14); ctx.scale(s, s);
|
|
1271
|
+
ctx.font = `900 ${Math.round(sz)}px Fraunces, Georgia, serif`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
|
1272
|
+
const w = ctx.measureText(f.text).width + sz * 0.5;
|
|
1273
|
+
ctx.lineWidth = 4; ctx.strokeStyle = Art.INKS.dusk.poppy; ctx.strokeRect(-w / 2, -sz * 0.62, w, sz * 1.18);
|
|
1274
|
+
ctx.lineJoin = 'round'; ctx.lineWidth = sz * 0.16; ctx.strokeStyle = Art.INKS.dusk.paper; ctx.strokeText(f.text, 0, sz * 0.04);
|
|
1275
|
+
ctx.fillStyle = Art.INKS.dusk.poppy; ctx.fillText(f.text, 0, sz * 0.04);
|
|
1276
|
+
ctx.restore();
|
|
1277
|
+
}
|
|
1278
|
+
else if (f.type === 'petal') {
|
|
1279
|
+
const k = age / 1.1; if (k >= 1) { fx.splice(i, 1); continue; }
|
|
1280
|
+
const x = f.x + f.vx * age + Math.sin(age * 7 + i) * 8, y = f.y + f.vy * age + 180 * age * age;
|
|
1281
|
+
ctx.save(); ctx.globalAlpha = 1 - k * k; ctx.translate(x, y); ctx.rotate(f.spin * age); ctx.scale(f.s, f.s);
|
|
1282
|
+
const pts = Art.ellipsePts(0, 0, 7, 3.6, 12, i, 0.12); Art.fill(ctx, pts, Art.mix('#e07a3a', '#6b4a2a', Math.min(1, k * 2.5))); Art.ink(ctx, pts, 1.6, Art.INKS.dusk.ink, i);
|
|
1283
|
+
ctx.restore();
|
|
1284
|
+
}
|
|
1285
|
+
else if (f.type === 'time') { // what a sting took or an apple gave, said at the sun
|
|
1286
|
+
if (age < 0) continue; const k = age / 0.9; if (k >= 1) { fx.splice(i, 1); continue; }
|
|
1287
|
+
const s = Scene.sunAt(L, pShown); Scene.pop(ctx, clamp(s.x, 50, W - 50), s.y + s.r * 1.9, f.text, k, Math.max(18, L.skyH * 0.13), f.hot);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
if (mode === 'title' && titleHog && titleHog.phase !== 'drop' && clock - titleHog.t0 > 0.6) {
|
|
1291
|
+
const h = L.holes[4]; Scene.hand(ctx, h.x + h.r * 0.12, h.y - h.r * 0.2, Math.max(0.8, h.r / 50), ((clock - titleHog.t0 - 0.6) * 0.8) % 1);
|
|
1292
|
+
}
|
|
1293
|
+
Scene.roller(ctx, night);
|
|
1294
|
+
Scene.fireflies(ctx, L, clock, night);
|
|
1295
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
1296
|
+
ctx.globalAlpha = 1 - night * 0.6; Art.mottle(ctx, W, H); ctx.globalAlpha = 1;
|
|
1297
|
+
}
|
|
1298
|
+
let timeScale = 1;
|
|
1299
|
+
function frame(ts) {
|
|
1300
|
+
const dt = Math.min(0.05, Math.max(0, (ts - last) / 1000)) * timeScale; last = ts; clock += dt;
|
|
1301
|
+
if (mode === 'title' && titleHog && titleHog.phase === 'rise' && clock - titleHog.t0 > C.RISE) titleHog = {phase: 'up', t0: titleHog.t0 + C.RISE};
|
|
1302
|
+
if (mode === 'play') { const before = core.streak; handle(C.step(core, dt), before); }
|
|
1303
|
+
else if (mode === 'night') {
|
|
1304
|
+
C.step(core, dt);
|
|
1305
|
+
night = clamp((clock - modeAt - 0.3) / 0.75, 0, 1); night = night * night * (3 - 2 * night);
|
|
1306
|
+
if (clock - modeAt > 1.5) finish();
|
|
1307
|
+
}
|
|
1308
|
+
if (mode === 'play') { const ws = core.holes.filter(e => e && e.kind === 'wasp' && (e.phase === 'up' || e.phase === 'rise')); Sound.wasps(ws.length, ws.length ? ws.reduce((a, e) => a + panOf(L.holes[e.hole]), 0) / ws.length : 0); }
|
|
1309
|
+
// the score tag counts up to what was earned
|
|
1310
|
+
if (scoreShown !== scoreTo) { scoreShown += (scoreTo - scoreShown) * Math.min(1, dt * 14); if (Math.abs(scoreTo - scoreShown) < 1) scoreShown = scoreTo; scoreEl.textContent = fmt(scoreShown); }
|
|
1311
|
+
if (core && mode === 'play') {
|
|
1312
|
+
// tick the last seconds on a woodblock
|
|
1313
|
+
const n = Math.ceil(core.left); if (n <= 5 && n !== frame.lastTick) { frame.lastTick = n; if (n > 0) Sound.tick(n === 1); }
|
|
1314
|
+
} else frame.lastTick = 99;
|
|
1315
|
+
Sound.tick2();
|
|
1316
|
+
draw();
|
|
1317
|
+
requestAnimationFrame(frame);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// ------------------------------------------------------------------ go
|
|
1321
|
+
resize();
|
|
1322
|
+
showTitle();
|
|
1323
|
+
const go = () => { if (__ppDead) return; ready = true; document.body.classList.add('ready'); last = performance.now(); requestAnimationFrame(frame); if (__wv.ready) __wv.ready(); };
|
|
1324
|
+
(document.fonts && document.fonts.load ? Promise.race([document.fonts.load('900 40px Fraunces'), new Promise(r => setTimeout(r, 1500))]) : Promise.resolve()).then(go, go);
|
|
1325
|
+
// for the tests and the screenshot tools
|
|
1326
|
+
window.__pp = {get mode() { return mode; }, get core() { return core; }, get L() { return L; }, start, tap: tapHole, finish,
|
|
1327
|
+
set timeScale(v) { timeScale = v; },
|
|
1328
|
+
// put something in a burrow now (for filming and tests): kind 'hog' | 'wasp'
|
|
1329
|
+
spawn(hole, kind, apple = false, up = 1.2) { const c = core; c.holes[hole] = {id: c.nextId++, kind, apple, hole, phase: 'warn', t0: c.t, warn: 0.28, up, upAt: 0}; c.nextSpawn = c.t + 99; },
|
|
1330
|
+
hold(on) { core.nextSpawn = on ? core.t + 9999 : core.t; }};
|
|
1331
|
+
})();
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
if (__hadRaf) window.requestAnimationFrame = _raf; else delete window.requestAnimationFrame;
|
|
1335
|
+
if (__hadWae) window.addEventListener = _wae; else delete window.addEventListener;
|
|
1336
|
+
if (__hadDae) document.addEventListener = _dae; else delete document.addEventListener;
|
|
1337
|
+
|
|
1338
|
+
__ppTeardown = () => {
|
|
1339
|
+
__ppDead = true;
|
|
1340
|
+
for (const id of __ppRaf) { try { cancelAnimationFrame(id); } catch (e) {} }
|
|
1341
|
+
for (const [tgt, t, fn, o] of __ppEls) { try { tgt.removeEventListener(t, fn, o); } catch (e) {} }
|
|
1342
|
+
__ppRaf.clear(); __ppEls.length = 0;
|
|
1343
|
+
try { Sound.setMuted(true); } catch (e) {}
|
|
1344
|
+
try { stage.innerHTML = ''; } catch (e) {}
|
|
1345
|
+
};
|
|
1346
|
+
},
|
|
1347
|
+
destroy() { if (__ppTeardown) { const t = __ppTeardown; __ppTeardown = null; t(); } }
|
|
1348
|
+
});
|