All projects
3D / WebGL3d

Sketchbook

Visit live
1 views 0 copiesFree

Sign in to take this project

Sign in to copy the source, prompt and SKILL.md.

DetailsPublished
Version
v1.0
Motion
Micro interaction
Updated
Nov 25, 2026
sketchbook.html
1<!doctype html>
2<html lang="en">
3<head><script>function __threeuiStorageImage(...args){const image=new Image(...args);const property=Object.getOwnPropertyDescriptor(HTMLImageElement.prototype,"src");Object.defineProperty(image,"src",{configurable:true,get(){return property.get.call(this)},set(value){try{const url=new URL(value,document.baseURI);if(this.crossOrigin===null&&(url.href.startsWith("https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/")||url.origin===new URL(document.baseURI).origin))this.crossOrigin="anonymous"}catch{}property.set.call(this,value)}});return image;}
4</script>
5<meta charset="utf-8">
6<meta name="viewport" content="width=device-width, initial-scale=1">
7<title>Meng To</title>
8<meta name="description" content="designer, creator, AI educator — Singapore">
9<style>
10@font-face{font-family:'Instrument Serif';font-style:normal;font-weight:400;font-display:block;
11 src:url(https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/embedded/60c06664b5a95c7de6cc3e00d1f9034d78bd1e40b564016b241674449a067d4d.woff2) format('woff2')}
12@font-face{font-family:'Instrument Serif';font-style:italic;font-weight:400;font-display:block;
13 src:url(https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/embedded/6ee678c33f388dd7ba59700ebea635deb98821baafd817b09891f7927177f702.woff2) format('woff2')}
14@font-face{font-family:'Newsreader';font-style:normal;font-weight:200 600;font-display:swap;
15 src:url(https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/dcec2e68141a33903e3b6cc1/newsreader.woff2) format('woff2')}
16
17:root{
18 --paper:#ece7dc;
19 --ink:#2b2721;
20 --ink-soft:rgba(43,39,33,.58);
21 --ink-faint:rgba(43,39,33,.36);
22 --hairline:rgba(43,39,33,.14);
23 --earth:#9a6a3e;
24 --display:'Instrument Serif',"New York",Georgia,'Times New Roman',serif;
25 --font:'Newsreader',"New York",Georgia,'Times New Roman',serif;
26 --track-caps:.24em;
27 --track-nav:.06em;
28}
29*{box-sizing:border-box}
30html,body{margin:0;padding:0}
31html{-webkit-text-size-adjust:100%}
32body{
33 font-family:var(--font);font-weight:400;background:var(--paper);color:var(--ink);
34 -webkit-font-smoothing:antialiased;overflow-x:hidden;
35}
36a{color:inherit;text-decoration:none}
37button{font:inherit}
38::selection{background:rgba(43,39,33,.85);color:var(--paper)}
39
40/* the painted ground the whole page sits on */
41.wash{
42 position:fixed;inset:0;z-index:-2;pointer-events:none;
43 background:url(https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/339abd2c649a11f725af9114/bg-wash.jpg) center top / cover no-repeat;
44 opacity:.85;
45}
46.wash:after{
47 content:"";position:absolute;inset:0;
48 background:linear-gradient(180deg,rgba(236,231,220,.25) 0%,rgba(236,231,220,.72) 58%,var(--paper) 88%);
49}
50
51/* ---------------- top bar ---------------- */
52.top{
53 position:fixed;top:0;left:0;right:0;z-index:500;
54 display:flex;flex-direction:column;align-items:center;gap:11px;
55 padding-inline:clamp(16px,4vw,48px);padding-block:18px 64px;pointer-events:none;text-align:center;
56}
57.top>*{pointer-events:auto}
58.top:before{
59 content:"";position:absolute;inset:0;z-index:-1;
60 background:linear-gradient(180deg,rgba(240,236,226,.94),rgba(240,236,226,.7) 48%,rgba(240,236,226,0));
61 -webkit-backdrop-filter:blur(14px) saturate(.95);backdrop-filter:blur(14px) saturate(.95);
62 -webkit-mask-image:linear-gradient(180deg,#000 46%,transparent);
63 mask-image:linear-gradient(180deg,#000 46%,transparent);
64}
65.top .name{
66 font-family:var(--display);font-size:clamp(24px,2.4vw,30px);letter-spacing:.01em;
67 white-space:nowrap;line-height:1;
68}
69.top nav{
70 display:flex;gap:clamp(14px,2vw,26px);font-size:15px;align-items:center;
71 letter-spacing:var(--track-nav);font-weight:300;
72}
73.top nav a{color:var(--ink-soft);transition:color .2s}
74.top nav a:hover,.top nav a[aria-current]{color:var(--ink)}
75.top nav .top-socials{
76 display:flex;align-items:center;gap:13px;margin-left:2px;padding-left:clamp(12px,1.6vw,20px);
77 border-left:1px solid var(--hairline);
78}
79.icon-btn{display:inline-flex;align-items:center;justify-content:center;padding:4px;color:var(--ink-soft);transition:color .2s}
80.icon-btn:hover{color:var(--ink)}
81.top .icon-btn svg{width:16px;height:16px;display:block}
82@media (max-width:640px){
83 .top{padding-inline:12px;padding-block:13px 50px;gap:8px}
84 .top .name{font-size:20px}
85 .top nav{gap:11px;font-size:13px}
86 .top nav .top-socials{gap:9px;padding-left:10px}
87 .top .icon-btn{padding:2px}
88 .top .icon-btn svg{width:14px;height:14px}
89}
90
91/* ---------------- hero ---------------- */
92.hero{
93 position:relative;display:grid;justify-items:center;align-content:center;
94 min-height:100svh;overflow-anchor:none;
95 padding:clamp(112px,13svh,152px) 0 clamp(72px,10svh,120px);
96}
97.botany{
98 position:absolute;bottom:0;width:clamp(120px,15vw,250px);opacity:.5;
99 pointer-events:none;user-select:none;z-index:0;
100}
101.botany.l{left:clamp(-40px,-1vw,0px);bottom:2%}
102.botany.r{right:clamp(-30px,0vw,10px);bottom:-2%;width:clamp(100px,12vw,200px)}
103@media (max-width:900px){.botany{display:none}}
104
105.hero-kicker{
106 font-size:12px;font-weight:400;letter-spacing:var(--track-caps);text-align:center;
107 color:var(--ink-soft);margin:0 0 clamp(22px,3.4vh,40px);text-transform:uppercase;
108}
109.hero-down{
110 position:absolute;bottom:30px;left:50%;transform:translateX(-50%);border:0;background:transparent;
111 padding:10px 14px;color:var(--ink);cursor:pointer;-webkit-tap-highlight-color:transparent;
112 animation:cue-breathe 2.6s ease-in-out infinite;z-index:3;
113}
114.hero-down:hover{animation:none;opacity:1}
115@keyframes cue-breathe{0%,100%{opacity:.15}50%{opacity:.7}}
116@media (prefers-reduced-motion:reduce){.hero-down{animation:none;opacity:.5}}
117
118/* ---------------- sketchbook ---------------- */
119.hero,.hero *{-webkit-user-select:none;-moz-user-select:none;user-select:none}
120.hero img{-webkit-user-drag:none;user-drag:none}
121.sb-wrap{display:grid;justify-items:center;gap:20px;width:100%;position:relative;z-index:2}
122.sb-stage{
123 display:flex;align-items:center;justify-content:center;width:100%;
124 position:relative;
125 touch-action:pan-y;
126}
127.sb-arrow{
128 flex:none;display:inline-flex;align-items:center;justify-content:center;padding:6px 2px;
129 border:0;background:transparent;color:var(--ink-faint);cursor:pointer;transition:color .2s;
130 -webkit-tap-highlight-color:transparent;z-index:8;
131}
132.sb-arrow:hover{color:var(--ink)}
133
134/* The box is the book's own untransformed frame: the loupe lives here, on
135 the desk, while only .sb-tilt leans and scales underneath it. */
136.sb-3d{
137 position:relative;flex:1 1;min-width:0;max-width:900px;
138 perspective:1750px;perspective-origin:50% 46%;
139}
140.sb-tilt{
141 position:relative;
142 transform-style:preserve-3d;
143 transform:rotateX(var(--rx,0deg)) rotateY(var(--ry,0deg)) scale(var(--zoom,1));
144 will-change:transform;
145}
146.sb-book{position:relative;width:100%;aspect-ratio:1760/1240;transform-style:preserve-3d;z-index:1}
147
148/* The book sits on a surface, so its shadow is a soft pool underneath —
149 no box, no filter on the artwork, nothing with an edge of its own.
150 Both blobs fade to zero well inside their own bounds, and both ease
151 off while a leaf is in the air. */
152.sb-cast{position:absolute;pointer-events:none;z-index:0}
153.sb-cast.ambient{
154 left:5%;right:5%;top:27%;bottom:2%;
155 background:radial-gradient(50% 50% at 50% 58%,
156 rgba(58,44,26,.34) 0%,rgba(58,44,26,.19) 40%,rgba(58,44,26,0) 74%);
157 filter:blur(26px);
158 opacity:calc(1 - var(--shade,0) * .42);
159}
160.sb-cast.contact{
161 left:9%;right:9%;top:62%;bottom:10%;
162 background:radial-gradient(50% 44% at 50% 42%,
163 rgba(44,32,14,.40) 0%,rgba(44,32,14,.17) 48%,rgba(44,32,14,0) 78%);
164 filter:blur(11px);
165 opacity:calc(1 - var(--shade,0) * .5);
166}
167.sb-cast.hair{
168 left:12%;right:12%;top:70%;bottom:17%;
169 background:radial-gradient(50% 52% at 50% 40%,
170 rgba(40,28,10,.34) 0%,rgba(40,28,10,0) 76%);
171 filter:blur(4px);
172 opacity:calc(1 - var(--shade,0) * .62);
173}
174.sb-full{position:absolute;inset:0}
175.sb-full img{width:100%;height:auto;display:block}
176.sb-half{position:absolute;top:0;bottom:0;width:50%;overflow-x:clip;overflow-y:visible}
177.sb-half.left{left:0}
178.sb-half.right{left:50%}
179.sb-half-img{width:200%;max-width:none;height:auto;display:block}
180.sb-half-img.right{margin-left:-100%}
181/* the shadow the lifting leaf throws onto the page beneath it */
182.gutter-shade{
183 position:absolute;top:var(--pg,21.8%);bottom:var(--pg,21.8%);width:46%;
184 pointer-events:none;opacity:calc(var(--shade,0) * .62);
185 -webkit-mask-image:linear-gradient(180deg,transparent 0,#000 5.2%,#000 94.8%,transparent 100%);
186 mask-image:linear-gradient(180deg,transparent 0,#000 5.2%,#000 94.8%,transparent 100%);
187}
188.gutter-shade.left{right:0;background:linear-gradient(270deg,rgba(52,38,20,.30),rgba(52,38,20,0) 82%)}
189.gutter-shade.right{left:0;background:linear-gradient(90deg,rgba(52,38,20,.24),rgba(52,38,20,0) 82%)}
190
191/* ---- the turning leaf: nested strips forming a curved surface ---- */
192.curl{
193 position:absolute;top:0;height:100%;
194 width:calc(var(--bw,0px) * var(--span));
195 transform-style:preserve-3d;z-index:6;
196}
197.curl.next{left:50%;transform-origin:left center;transform:rotateY(calc(-1 * var(--tt,0deg)))}
198.curl.prev{right:50%;transform-origin:right center;transform:rotateY(var(--tt,0deg))}
199.strip{
200 position:absolute;top:0;height:100%;
201 width:calc(var(--bw,0px) * var(--span) / var(--n));
202 transform-style:preserve-3d;
203}
204.curl.next .strip{transform-origin:left center}
205.curl.prev .strip{transform-origin:right center}
206.curl.next>.strip{left:0}
207.curl.prev>.strip{right:0;left:auto}
208.curl.next .strip .strip{left:100%;transform:rotateY(var(--td,0deg))}
209.curl.prev .strip .strip{right:100%;transform:rotateY(calc(-1 * var(--td,0deg)))}
210.face{
211 position:absolute;top:0;bottom:0;left:0;right:-1.1px;
212 backface-visibility:hidden;-webkit-backface-visibility:hidden;
213 background-repeat:no-repeat;background-size:var(--bw,0px) auto;
214}
215.face.back{transform:rotateY(180deg)}
216.face .sh,.face .gl{
217 -webkit-mask-image:linear-gradient(180deg,transparent 0,#000 5.2%,#000 94.8%,transparent 100%);
218 mask-image:linear-gradient(180deg,transparent 0,#000 5.2%,#000 94.8%,transparent 100%);
219}
220.strip.edge .face .sh,.strip.edge .face .gl{
221 -webkit-mask-image:linear-gradient(180deg,transparent 0,#000 9%,#000 91%,transparent 100%),var(--hf);
222 mask-image:linear-gradient(180deg,transparent 0,#000 9%,#000 91%,transparent 100%),var(--hf);
223 -webkit-mask-composite:source-in;mask-composite:intersect;
224}
225.curl.next .strip.edge .face.front,.curl.prev .strip.edge .face.back{
226 --hf:linear-gradient(90deg,#000 0 22%,transparent 96%);
227}
228.curl.next .strip.edge .face.back,.curl.prev .strip.edge .face.front{
229 --hf:linear-gradient(270deg,#000 0 22%,transparent 96%);
230}
231.face .sh{position:absolute;left:0;right:0;top:var(--pg,21.8%);bottom:var(--pg,21.8%);pointer-events:none}
232.curl.next .face.front .sh,.curl.prev .face.back .sh{
233 background:linear-gradient(90deg,rgba(58,43,20,var(--a1,0)),rgba(58,43,20,var(--a2,0)));
234}
235.curl.next .face.back .sh,.curl.prev .face.front .sh{
236 background:linear-gradient(90deg,rgba(58,43,20,var(--a2,0)),rgba(58,43,20,var(--a1,0)));
237}
238.face .gl{
239 position:absolute;left:0;right:0;top:var(--pg,21.8%);bottom:var(--pg,21.8%);
240 pointer-events:none;background:#fffaf0;
241 opacity:calc(var(--shade,0) * var(--lit,1) * var(--lit,1) * .20);
242}
243
244/* ---- the loupe: a real magnifier lying on the page. Pick it up and
245 drag it across the book; it stays where you put it. ---- */
246.loupe{
247 position:absolute;left:0;top:0;
248 width:var(--lr,270px);height:var(--lr,270px);
249 pointer-events:none;z-index:80;opacity:0;
250 transition:opacity .25s ease;
251 will-change:transform;
252}
253.loupe.on{opacity:1}
254.loupe.held .ring{cursor:grabbing}
255.loupe .ring{
256 position:absolute;inset:0;border-radius:50%;
257 pointer-events:auto;cursor:grab;
258 padding:calc(var(--lr,270px) * .058);
259 box-shadow:
260 0 1px 2px rgba(58,44,26,.30),
261 0 10px 18px rgba(58,44,26,.24),
262 0 26px 40px rgba(58,44,26,.20),
263 0 48px 66px rgba(58,44,26,.13);
264}
265/* the bezel is an annulus, so the glass really is see-through */
266.loupe .ring:before{
267 content:"";position:absolute;inset:0;border-radius:50%;pointer-events:none;
268 background:linear-gradient(146deg,
269 #fdf7e9 0%,#e6d7b4 14%,#b69d70 32%,#7d6740 50%,
270 #cdbb92 66%,#f4ead3 80%,#9b8459 100%);
271 box-shadow:
272 inset 0 1px 1px rgba(255,255,255,.8),
273 inset 0 -2px 3px rgba(70,52,26,.5);
274 -webkit-mask-image:radial-gradient(circle closest-side at 50% 50%,transparent 0 88.2%,#000 89.8% 100%);
275 mask-image:radial-gradient(circle closest-side at 50% 50%,transparent 0 88.2%,#000 89.8% 100%);
276}
277/* the handle, drawn before the bezel so the ring covers its inner end */
278.loupe .grip{
279 position:absolute;left:50%;top:50%;
280 width:calc(var(--lr,270px) * .74);height:calc(var(--lr,270px) * .125);
281 transform-origin:0 50%;
282 transform:rotate(40deg) translate(calc(var(--lr,270px) * .33),-50%);
283 border-radius:calc(var(--lr,270px) * .06);
284 pointer-events:auto;cursor:grab;
285 background:
286 linear-gradient(180deg,rgba(255,255,255,.46) 0 13%,rgba(255,255,255,0) 44%,
287 rgba(0,0,0,.26) 100%),
288 linear-gradient(90deg,#d9bd82 0 14%,#a9884e 14% 20%,#6d4c2b 20% 62%,
289 #5a3d22 62% 92%,#7a563180 92% 100%);
290 box-shadow:0 8px 15px rgba(58,44,26,.26),0 18px 26px rgba(58,44,26,.14);
291}
292.lens{
293 position:relative;display:block;width:100%;height:100%;border-radius:50%;
294 background-repeat:no-repeat;overflow:hidden;
295 box-shadow:
296 inset 0 0 0 1px rgba(52,40,22,.55),
297 inset 0 4px 12px rgba(40,30,14,.28),
298 inset 0 -7px 16px rgba(255,250,240,.14);
299}
300.lens .mag{display:none}
301/* A second copy of the book, sitting beside the glass outside the tilt, and
302 scaled about whichever page point the glass is currently over. */
303.zoomwrap{
304 position:absolute;inset:0;overflow:hidden;pointer-events:none;z-index:2;
305 opacity:0;
306}
307.zoominner{position:absolute;inset:0;transform-origin:0 0}
308.lens:before,.lens:after{content:"";position:absolute;inset:0;border-radius:50%;pointer-events:none}
309.lens:before{z-index:1}
310.lens:after{z-index:2}
311/* the glass bends and darkens toward its rim, with a faint colour fringe */
312.lens:before{
313 background:radial-gradient(circle at 50% 50%,
314 rgba(0,0,0,0) 54%,rgba(58,44,26,.10) 76%,rgba(46,34,16,.34) 100%);
315 box-shadow:
316 inset 0 0 0 2px rgba(130,162,196,.26),
317 inset 0 0 0 4px rgba(206,158,112,.15);
318}
319/* the dome: one broad specular and a tight crescent opposite it */
320.lens:after{
321 background:
322 radial-gradient(36% 26% at 29% 19%,rgba(255,255,255,.30),rgba(255,255,255,0) 76%),
323 radial-gradient(24% 16% at 74% 86%,rgba(255,255,255,.12),rgba(255,255,255,0) 80%),
324 linear-gradient(150deg,rgba(255,255,255,.06) 0 18%,rgba(255,255,255,0) 42%);
325}
326
327/* ---- controls ---- */
328.sb-tools{
329 display:flex;align-items:center;gap:6px;
330 border:1px solid var(--hairline);border-radius:999px;
331 padding:5px 7px;background:rgba(250,246,238,.62);
332 -webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);
333}
334.tool{
335 width:28px;height:28px;display:inline-flex;align-items:center;justify-content:center;
336 border:0;border-radius:50%;background:transparent;color:var(--ink-soft);
337 cursor:pointer;transition:background-color .18s ease,color .18s ease;
338}
339.tool:hover{background:rgba(255,252,244,.9);color:var(--ink)}
340.tool[aria-pressed="true"]{background:rgba(154,106,62,.16);color:var(--earth)}
341.tool:disabled{opacity:.32;cursor:default;background:transparent}
342.tool svg{width:15px;height:15px;display:block}
343.tool-sep{width:1px;height:17px;background:var(--hairline);margin:0 2px}
344.zoom-read{
345 font-size:11px;letter-spacing:.1em;color:var(--ink-faint);
346 min-width:40px;text-align:center;font-variant-numeric:tabular-nums;
347}
348@media (pointer:coarse){.loupe{display:none}}
349
350.sb-zone{position:absolute;top:0;bottom:0;border:0;background:transparent;cursor:grab;z-index:60;-webkit-tap-highlight-color:transparent}
351.sb-zone:active{cursor:grabbing}
352.sb-prev{left:0;width:50%}
353.sb-next{right:0;width:50%}
354
355.sb-captions{display:grid;justify-items:center}
356.sb-captions>*{grid-area:1/1;margin:0}
357.sb-caption{font-size:13px;letter-spacing:var(--track-caps);text-transform:uppercase;color:var(--ink-soft);
358 animation:sb-cap-in .5s ease both}
359.sb-caption.live{animation:none}
360@keyframes sb-cap-in{0%{opacity:0}}
361@keyframes sb-cap-out{to{opacity:0}}
362.sb-hint{
363 margin:0;font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--ink-faint);
364 transition:opacity .4s ease;
365}
366.sb-hint.gone{opacity:0}
367.sb-wrap.intro .sb-full img,.sb-wrap.intro .sb-half-img{filter:url(#sb-mblur-1)}
368.sb-wrap.intro.b2 .sb-full img,.sb-wrap.intro.b2 .sb-half-img{filter:url(#sb-mblur-2)}
369.sb-wrap.intro .sb-caption{animation:none}
370.sb-wrap.intro .sb-caption.cap-out{display:none}
371@media (max-width:640px){
372 .hero-kicker{font-size:10.5px;letter-spacing:.16em}
373 .sb-wrap{width:100vw;margin-inline:calc(50% - 50vw)}
374 .sb-arrow{position:absolute;top:50%;transform:translateY(-50%);z-index:70;padding:12px 6px}
375 .sb-arrow.left{left:2px}
376 .sb-arrow.right{right:2px}
377 .sb-3d{max-width:none}
378 .sb-hint{font-size:9.5px;letter-spacing:.1em;padding:0 16px;text-align:center}
379}
380
381/* ---------------- painted rules + sections ---------------- */
382.rule{
383 display:block;width:min(1080px,86vw);margin:clamp(30px,6vh,64px) auto;
384 height:clamp(26px,4vw,46px);
385 background:url(https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/339abd2c649a11f725af9114/divider.png) center / 100% auto no-repeat;
386 opacity:.5;
387}
388.rule.short{width:min(420px,52vw);opacity:.4}
389.section-label{
390 font-size:11px;letter-spacing:var(--track-caps);text-transform:uppercase;
391 color:var(--ink-faint);margin:0 0 18px;
392}
393.about{
394 position:relative;max-width:1080px;margin:0 auto;
395 padding:0 clamp(20px,5vw,48px);
396 display:grid;grid-template-columns:minmax(0,1fr) auto;gap:clamp(24px,5vw,60px);align-items:start;
397}
398.bio{font-size:clamp(17px,1.7vw,20px);line-height:1.74;letter-spacing:.005em;margin:0;font-weight:300;max-width:56ch}
399.bio-link{color:var(--ink);text-decoration:underline;text-decoration-color:rgba(43,39,33,.28);
400 text-underline-offset:4px;transition:text-decoration-color .2s}
401.bio-link:hover{text-decoration-color:var(--ink)}
402.bloom{width:clamp(150px,17vw,260px);opacity:.9;user-select:none;align-self:center}
403@media (max-width:760px){
404 .about{grid-template-columns:1fr}
405 .bloom{width:170px;justify-self:center}
406}
407
408.plates{max-width:1080px;margin:0 auto;padding:0 clamp(20px,5vw,48px)}
409.plate-list{list-style:none;margin:0;padding:0;border-top:1px solid var(--hairline)}
410.plate{
411 display:grid;grid-template-columns:3.4em minmax(0,1fr) auto;gap:18px;align-items:baseline;
412 width:100%;padding:15px 4px;border:0;border-bottom:1px solid var(--hairline);
413 background:transparent;text-align:left;cursor:pointer;color:inherit;
414 transition:background-color .22s ease,padding-left .22s ease;
415}
416.plate:hover,.plate[aria-current="true"]{background:rgba(255,252,244,.5);padding-left:12px}
417.plate .n{font-size:12px;color:var(--ink-faint);letter-spacing:var(--track-nav)}
418.plate .t{font-family:var(--display);font-size:clamp(19px,2.1vw,26px)}
419.plate .p{font-size:12.5px;color:var(--ink-faint);letter-spacing:.08em;text-transform:uppercase;text-align:right}
420.plate[aria-current="true"] .p{color:var(--earth)}
421
422.foot{font-size:11.5px;letter-spacing:var(--track-caps);text-transform:uppercase;
423 color:var(--ink-faint);text-align:center;padding-bottom:44px}
424</style>
425</head>
426<body>
427<div class="wash" aria-hidden="true"></div>
428<main class="page home">
429
430 <header class="top">
431 <a class="name" href="#">Meng To</a>
432 <nav>
433 <a href="#plates">Journal</a>
434 <a href="#about">About</a>
435 <a href="#contact">Contact</a>
436 <div class="top-socials">
437 <a href="#" class="icon-btn" aria-label="X"><svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M17.7 2.6h3.3l-7.2 8.2 8.5 11.2h-6.7l-5.2-6.9-6 6.9H1.1l7.7-8.8L.7 2.6h6.9l4.7 6.3 5.4-6.3Zm-1.2 17.5h1.8L7.6 4.4H5.7l10.8 15.7Z"/></svg></a>
438 <a href="#" class="icon-btn" aria-label="LinkedIn"><svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M4.9 3.5a2.1 2.1 0 1 1 0 4.2 2.1 2.1 0 0 1 0-4.2ZM3.1 9.3h3.6v11.6H3.1V9.3Zm6 0h3.4v1.6h.05c.48-.9 1.65-1.85 3.4-1.85 3.63 0 4.3 2.35 4.3 5.4v6.45h-3.6v-5.72c0-1.36-.02-3.12-1.92-3.12-1.92 0-2.22 1.48-2.22 3.02v5.82H9.1V9.3Z"/></svg></a>
439 <a href="#" class="icon-btn" aria-label="Instagram"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><rect x="2.6" y="2.6" width="18.8" height="18.8" rx="5.4"/><circle cx="12" cy="12" r="4.4"/><circle cx="17.6" cy="6.4" r="1.15" fill="currentColor" stroke="none"/></svg></a>
440 <a href="#contact" class="icon-btn" aria-label="Email"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><rect x="2.4" y="4.6" width="19.2" height="14.8" rx="2.4"/><path d="m3.2 6.4 8.8 6.6 8.8-6.6"/></svg></a>
441 </div>
442 </nav>
443 </header>
444
445 <section id="sketchbook" class="hero">
446 <img crossorigin="anonymous" class="botany l" src="https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/339abd2c649a11f725af9114/botany-left.png" alt="" aria-hidden="true">
447 <img crossorigin="anonymous" class="botany r" src="https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/339abd2c649a11f725af9114/botany-right.png" alt="" aria-hidden="true">
448
449 <p class="hero-kicker">Designer / Creator / AI Educator / Founder @ Singapore</p>
450
451 <div class="sb-wrap" id="sbWrap">
452 <svg width="0" height="0" style="position:absolute" aria-hidden="true">
453 <filter id="sb-mblur-1"><feGaussianBlur stdDeviation="5 0"/></filter>
454 <filter id="sb-mblur-2"><feGaussianBlur stdDeviation="14 0"/></filter>
455 </svg>
456 <div class="sb-stage" id="sbStage">
457 <button class="sb-arrow left" id="sbLeft" aria-label="previous page">
458 <svg viewBox="0 0 14 44" width="14" height="44" fill="none" aria-hidden="true"><polyline points="11,3 3,22 11,41" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"/></svg>
459 </button>
460 <div class="sb-3d" id="sb3d">
461 <div class="sb-tilt" id="sbTilt">
462 <div class="sb-cast ambient" aria-hidden="true"></div>
463 <div class="sb-cast contact" aria-hidden="true"></div>
464 <div class="sb-cast hair" aria-hidden="true"></div>
465 <div class="sb-book" id="sbBook"></div>
466 </div>
467 <div class="zoomwrap" id="zoomWrap" aria-hidden="true"><div class="zoominner" id="zoomInner"></div></div>
468 <div class="loupe" id="loupe"><span class="grip"></span><span class="ring"><span class="lens" id="loupeLens"><span class="mag" id="loupeMag"></span></span></span></div>
469 </div>
470 <button class="sb-arrow right" id="sbRight" aria-label="next page">
471 <svg viewBox="0 0 14 44" width="14" height="44" fill="none" aria-hidden="true"><polyline points="3,3 11,22 3,41" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"/></svg>
472 </button>
473 </div>
474 <div class="sb-captions" id="sbCaptions"></div>
475 <div class="sb-tools" role="group" aria-label="view controls">
476 <button class="tool" id="zOut" aria-label="zoom out"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><circle cx="8.6" cy="8.6" r="5.6"/><path d="M12.8 12.8 17.4 17.4M6.2 8.6h4.8"/></svg></button>
477 <span class="zoom-read" id="zRead">100%</span>
478 <button class="tool" id="zIn" aria-label="zoom in"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><circle cx="8.6" cy="8.6" r="5.6"/><path d="M12.8 12.8 17.4 17.4M6.2 8.6h4.8M8.6 6.2v4.8"/></svg></button>
479 <span class="tool-sep" aria-hidden="true"></span>
480 <button class="tool" id="loupeBtn" aria-label="magnifier" aria-pressed="true"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><circle cx="8.8" cy="8.8" r="5.8"/><path d="M13 13l4.4 4.4"/><path d="M6.4 7.2a3.2 3.2 0 0 1 2.4-1.4" opacity=".55"/></svg></button>
481 </div>
482 <p class="sb-hint" id="sbHint">Drag the page to turn · Drag the glass across it</p>
483 </div>
484
485 <button class="hero-down" id="heroDown" aria-label="scroll to about">
486 <svg viewBox="0 0 44 22" width="34" height="17" fill="none" aria-hidden="true">
487 <polyline points="3,3 22,11 41,3" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"/>
488 <polyline points="3,11 22,19 41,11" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"/>
489 </svg>
490 </button>
491 </section>
492
493 <div class="rule" aria-hidden="true"></div>
494
495 <section id="about" class="about">
496 <div>
497 <p class="section-label">About</p>
498 <p class="bio">Meng To is a designer, creator, and AI educator based in Singapore. He is the founder of <a class="bio-link" href="#">Design+Code</a>, where for over a decade he has taught designers and developers to build real apps — from Sketch and Xcode through SwiftUI, and now the AI tools that let one person ship what used to take a team. His work lives on the seam between craft and code: teaching designers to build, and builders to see. This sketchbook is the other half of that — the city looked at slowly, in <a class="bio-link" href="#">ink and a little colour</a>: shophouse shutters, hawker tents, the bay at dusk.</p>
499 </div>
500 <img crossorigin="anonymous" class="bloom" src="https://ublctyddhtbgaersvxxb.supabase.co/storage/v1/object/public/threeui-media/scene-images/339abd2c649a11f725af9114/bloom.png" alt="" aria-hidden="true">
501 </section>
502
503 <div class="rule short" aria-hidden="true"></div>
504
505 <section id="plates" class="plates">
506 <p class="section-label">Plates</p>
507 <ol class="plate-list" id="plateList"></ol>
508 </section>
509
510 <div class="rule short" aria-hidden="true"></div>
511 <p class="foot" id="contact">Singapore · Sketchbook · <a href="#" class="bio-link">hello@mengto.com</a></p>
512</main>
513
514<script>
515/* =====================================================================
516 Meng To — sketchbook hero.
517 Spreads are transparent PNGs of an open sketchbook generated with
518 Higgsfield. The leaf that turns is a real curved surface: a chain of
519 nested strips whose tangent sweeps through an arc, so the page bends
520 the way paper bends instead of pivoting like a flat door.
521 ===================================================================== */
522const Q=new URLSearchParams(location.search);
523const DIR='meng-to-sketchbook/';
524const PAGES=[
525 {file:'marina-bay-sands.png', title:'Marina Bay Sands', place:'Bayfront'},
526 {file:'gardens-by-the-bay.png', title:'Gardens by the Bay', place:'Supertree Grove'},
527 {file:'merlion.png', title:'The Merlion', place:'Merlion Park'},
528 {file:'buddha-tooth.png', title:'Buddha Tooth Relic Temple', place:'Chinatown'},
529 {file:'joo-chiat.png', title:'Joo Chiat Shophouses', place:'Katong'},
530 {file:'lau-pa-sat.png', title:'Lau Pa Sat', place:'Raffles Quay'},
531 {file:'marina-bay-skyline.png', title:'Marina Bay Skyline', place:'The Bay'},
532 {file:'singapore-river.png', title:'Singapore River', place:'Boat Quay'},
533 {file:'botanic-gardens.png', title:'Botanic Gardens', place:'Tanglin'}
534];
535PAGES.forEach(p=>p.url=DIR+p.file);
536const M=PAGES.length, LAND=6;
537
538const wrap=document.getElementById('sbWrap');
539const stage=document.getElementById('sbStage');
540const sb3d=document.getElementById('sb3d');
541const book=document.getElementById('sbBook');
542const capBox=document.getElementById('sbCaptions');
543const hint=document.getElementById('sbHint');
544const REDUCED=matchMedia('(prefers-reduced-motion: reduce)').matches;
545
546/* ------------------------------------------------ the turning leaf */
547const N=18; /* strips — enough for a smooth curve */
548const SPAN=0.449; /* gutter → outer page edge, as a fraction */
549const BETA=0.60; /* peak curl of the arc, radians */
550let idx=0, turn=null; /* turn = {dir, from, to, t} */
551let strips=[]; /* the chain, kept for per-frame lighting */
552
553function el(t,c){const e=document.createElement(t);if(c)e.className=c;return e}
554function imgEl(i,side){
555 const im=new __threeuiStorageImage();im.className='sb-half-img '+side;
556 im.draggable=false;im.alt='';im.src=PAGES[i].url;return im;
557}
558
559function halfEl(pos,i){
560 const d=el('div','sb-half '+pos);
561 d.appendChild(imgEl(i,pos));
562 d.appendChild(el('div','gutter-shade '+pos));
563 return d;
564}
565/* build the strip chain once per turn; background offsets are pure
566 geometry, so they never need touching again while it animates */
567function buildCurl(dir,from,to){
568 strips=[];
569 const c=el('div','curl '+dir);
570 c.style.setProperty('--n',N);
571 c.style.setProperty('--span',SPAN);
572 let host=c;
573 for(let i=0;i<N;i++){
574 const s=el('div','strip');
575 s.style.setProperty('--i',i);
576 const gut='calc(var(--bw) * 0.5)';
577 const sw='calc(var(--bw) * '+SPAN+' / '+N+')';
578 const A='calc(-1 * ('+gut+' + '+i+' * '+sw+'))'; /* faces the from-page */
579 const B='calc('+(i+1)+' * '+sw+' - '+gut+')'; /* faces the to-page */
580 const f=el('div','face front'), b=el('div','face back');
581 const dress=(e,url,px)=>{
582 e.style.backgroundImage='url('+url+')';
583 e.style.backgroundPositionX=px;
584 };
585 dress(f,PAGES[from].url, dir==='next'?A:B);
586 dress(b,PAGES[to].url, dir==='next'?B:A);
587 f.appendChild(el('div','sh'));f.appendChild(el('div','gl'));
588 b.appendChild(el('div','sh'));b.appendChild(el('div','gl'));
589 s.appendChild(f);s.appendChild(b);
590 if(i===N-1)s.classList.add('edge');
591 host.appendChild(s);host=s;
592 strips.push(s);
593 }
594 return c;
595}
596function applyTurn(t){
597 const th=Math.PI*t; /* how far the leaf has swung */
598 const beta=BETA*Math.sin(Math.PI*t); /* it is flat at both ends */
599 const D=180/Math.PI;
600 const tt=th+beta, td=2*beta/N;
601 sb3d.style.setProperty('--tt',(tt*D).toFixed(2)+'deg');
602 sb3d.style.setProperty('--td',(td*D).toFixed(3)+'deg');
603 sb3d.style.setProperty('--shade',Math.sin(Math.PI*t).toFixed(3));
604 fadeCaption(t);
605 for(let i=0;i<strips.length;i++){
606 const l1=Math.abs(Math.cos(tt-i*td)); /* facing at this strip's near edge */
607 const l2=Math.abs(Math.cos(tt-(i+1)*td)); /* ...and at its far edge */
608 const st=strips[i].style;
609 st.setProperty('--lit',l1.toFixed(3));
610 st.setProperty('--a1',((1-l1)*.62).toFixed(3));
611 st.setProperty('--a2',((1-l2)*.62).toFixed(3));
612 }
613}
614function paint(){
615 book.textContent='';
616 if(!turn){
617 const f=el('div','sb-full');
618 const im=new __threeuiStorageImage();im.src=PAGES[idx].url;im.alt=PAGES[idx].title;
619 im.draggable=false;
620 f.appendChild(im);book.appendChild(f);
621 sb3d.style.setProperty('--shade','0');
622 }else{
623 const next=turn.dir==='next';
624 book.appendChild(halfEl('left', next?turn.from:turn.to));
625 book.appendChild(halfEl('right',next?turn.to:turn.from));
626 book.appendChild(buildCurl(turn.dir,turn.from,turn.to));
627 applyTurn(turn.t);
628 }
629 const a=el('button','sb-zone sb-prev'),b=el('button','sb-zone sb-next');
630 a.setAttribute('aria-label','previous page');b.setAttribute('aria-label','next page');
631 book.appendChild(a);book.appendChild(b);
632 layout();
633 caption();
634 marks();
635 if(typeof syncZoomLayer==='function')syncZoomLayer();
636 if(typeof placeLoupe==='function')placeLoupe();
637}
638function caption(){
639 capBox.textContent='';
640 capOut=capIn=null;
641 if(turn){
642 capOut=el('p','sb-caption live');capOut.textContent=PAGES[turn.from].title;capBox.appendChild(capOut);
643 capIn=el('p','sb-caption live');capIn.textContent=PAGES[turn.to].title;capBox.appendChild(capIn);
644 fadeCaption(turn.t);
645 }else{
646 const p=el('p','sb-caption');p.textContent=PAGES[idx].title;capBox.appendChild(p);
647 }
648}
649let capOut=null,capIn=null;
650function fadeCaption(t){
651 if(!capOut||!capIn)return;
652 /* the old title is gone before the new one arrives, so they never
653 sit on top of each other mid-drag */
654 const out=1-Math.max(0,Math.min(1,(t-0.10)/0.28));
655 const inn=Math.max(0,Math.min(1,(t-0.56)/0.30));
656 capOut.style.opacity=out.toFixed(3);
657 capIn.style.opacity=inn.toFixed(3);
658}
659function layout(){
660 sb3d.style.setProperty('--bw',book.clientWidth+'px');
661}
662addEventListener('resize',layout);
663
664/* ------------------------------------------------------ spring loop */
665let spring=null;
666function animateTo(target,onDone,stiff,damp){
667 spring={kind:'spring',v:0,target:target,done:onDone,k:stiff||150,c:damp||22};
668 kick();
669}
670/* the riffle wants a fixed tempo, not a spring settling time */
671function tweenTo(target,dur,onDone){
672 spring={kind:'tween',from:turn?turn.t:0,target:target,dur:dur,e:0,done:onDone};
673 kick();
674}
675let raf=null,last=0;
676function tick(now){
677 raf=null;
678 const dt=Math.min(0.032,(now-last)/1000||0.016);last=now;
679 if(spring&&turn){
680 const s=spring;
681 if(s.kind==='tween'){
682 s.e+=dt;
683 const k=Math.min(1,s.e/s.dur);
684 turn.t=s.from+(s.target-s.from)*k;
685 applyTurn(turn.t);
686 if(k>=1){spring=null;const d=s.done;d&&d();}
687 }else{
688 const x=turn.t-s.target;
689 s.v+= (-s.k*x - s.c*s.v)*dt;
690 turn.t+=s.v*dt;
691 if(Math.abs(turn.t-s.target)<0.002&&Math.abs(s.v)<0.02){
692 turn.t=s.target;spring=null;
693 applyTurn(turn.t);
694 const d=s.done;d&&d();
695 }else applyTurn(turn.t);
696 }
697 }
698 viewSpring();
699 const lmoved=loupeEase();
700 /* kick() may already have queued the next frame from a done-callback */
701 if((spring||viewActive||lmoved)&&raf===null) raf=requestAnimationFrame(tick);
702}
703function kick(){ if(raf===null){last=performance.now();raf=requestAnimationFrame(tick);} }
704
705/* ------------------------------------------- tilt + zoom of the book */
706const TILT_X=4.5, TILT_Y=7; /* degrees — deliberately restrained */
707const ZOOM_MIN=0.9, ZOOM_MAX=1.5;
708const view={rx:0,ry:0,z:1, trx:0,try_:0,tz:1};
709let viewActive=false;
710let lastZ=1;
711function applyView(){
712 sb3d.style.setProperty('--rx',view.rx.toFixed(2)+'deg');
713 sb3d.style.setProperty('--ry',view.ry.toFixed(2)+'deg');
714 sb3d.style.setProperty('--zoom',view.z.toFixed(3));
715 /* the glass stays put, but the page under it has moved */
716 if(view.z!==lastZ){lastZ=view.z;if(typeof placeLoupe==='function')placeLoupe();}
717}
718function viewSpring(){
719 const e=0.14;
720 let moved=false;
721 for(const [k,t] of [['rx','trx'],['ry','try_'],['z','tz']]){
722 const d=view[t]-view[k];
723 if(Math.abs(d)>0.0006){view[k]+=d*e;moved=true;}
724 else view[k]=view[t];
725 }
726 if(moved)applyView();
727 viewActive=moved;
728 return moved;
729}
730function setView(rx,ry,z){
731 view.trx=Math.max(-TILT_X,Math.min(TILT_X,rx));
732 view.try_=Math.max(-TILT_Y,Math.min(TILT_Y,ry));
733 view.tz=Math.max(ZOOM_MIN,Math.min(ZOOM_MAX,z));
734 viewActive=true;kick();
735 if(typeof syncZoom==='function')syncZoom();
736}
737/* the book leans toward the cursor — no dragging, and never far */
738function tiltTo(cx,cy){
739 if(drag)return; /* hold still while a page is being turned */
740 const r=book.getBoundingClientRect();
741 if(!r.width)return;
742 const nx=Math.max(-1,Math.min(1,(cx-(r.left+r.width/2))/(r.width*0.62)));
743 const ny=Math.max(-1,Math.min(1,(cy-(r.top+r.height/2))/(r.height*0.9)));
744 setView(-ny*TILT_X, nx*TILT_Y, view.tz);
745}
746addEventListener('pointermove',e=>{
747 if(e.pointerType==='touch')return;
748 tiltTo(e.clientX,e.clientY);
749},{passive:true});
750addEventListener('pointerout',e=>{if(!e.relatedTarget)setView(0,0,view.tz)});
751addEventListener('blur',()=>setView(0,0,view.tz));
752/* the wheel belongs to the page — zoom is on the toolbar, or a double click
753 to come back to 100% */
754stage.addEventListener('dblclick',()=>setView(view.trx,view.try_,1));
755
756/* ------------------------------------------------------- pointer work */
757let drag=null;
758function bookRect(){return book.getBoundingClientRect()}
759function hideHint(){hint.classList.add('gone')}
760
761stage.addEventListener('pointerdown',e=>{
762 if(e.button!==0)return;
763 e.preventDefault(); /* no text selection, no image drag */
764 const onBook=e.target.closest('.sb-zone');
765 stage.setPointerCapture(e.pointerId);
766 hideHint();
767 if(!onBook||introOn)return;
768 const r=bookRect();
769 const dir=(e.clientX-r.left)/r.width>0.5?'next':'prev';
770 startTurn(dir,0);
771 drag={dir:dir,x0:e.clientX,w:r.width,moved:0,vel:0,tPrev:performance.now()};
772});
773stage.addEventListener('pointermove',e=>{
774 if(!drag)return;
775 const dx=e.clientX-drag.x0;
776 drag.moved=Math.max(drag.moved,Math.abs(dx));
777 const raw=(drag.dir==='next'? -dx : dx)/(drag.w*0.62);
778 const t=Math.max(0,Math.min(1,raw));
779 const now=performance.now();
780 drag.vel=(t-(turn?turn.t:0))/Math.max(0.001,(now-drag.tPrev)/1000);
781 drag.tPrev=now;
782 if(turn){turn.t=t;applyTurn(t);}
783});
784function endDrag(e){
785 if(!drag)return;
786 const d=drag;drag=null;
787 if(!turn)return;
788 if(d.moved<6){ /* a tap, not a drag */
789 commit();return;
790 }
791 const go = turn.t>0.42 || d.vel>1.1;
792 if(go)commit(); else cancel();
793}
794stage.addEventListener('dragstart',e=>e.preventDefault());
795stage.addEventListener('selectstart',e=>e.preventDefault());
796stage.addEventListener('pointerup',endDrag);
797stage.addEventListener('pointercancel',endDrag);
798
799/* ------------------------------------------------------ turn control */
800function startTurn(dir,t){
801 spring=null;
802 if(turn){idx=turn.to;turn=null;} /* settle anything still in flight */
803 if(typeof shoveLoupe==='function')shoveLoupe(dir);
804 const from=idx;
805 turn={dir:dir,from:from,to:dir==='next'?(from+1)%M:(from-1+M)%M,t:t||0};
806 paint();
807}
808function commit(){
809 if(!turn)return;
810 if(REDUCED){idx=turn.to;turn=null;paint();return;}
811 animateTo(1,()=>{idx=turn.to;turn=null;paint();},170,26);
812 kick();
813}
814function cancel(){
815 if(!turn)return;
816 animateTo(0,()=>{turn=null;paint();},150,24);
817 kick();
818}
819function step(dir){
820 if(introOn)endIntro();
821 if(turn){ /* finish whatever is in flight first */ idx=turn.to;turn=null; }
822 startTurn(dir,0);commit();
823}
824function goTo(i){
825 if(introOn)endIntro();
826 if(i===idx)return;
827 if(turn){idx=turn.to;turn=null;}
828 const fwd=(i-idx+M)%M, back=(idx-i+M)%M;
829 if(Math.min(fwd,back)===1){step(fwd===1?'next':'prev');return;}
830 idx=i;paint();
831}
832document.getElementById('sbLeft').onclick=()=>step('prev');
833document.getElementById('sbRight').onclick=()=>step('next');
834addEventListener('keydown',e=>{
835 if(e.key!=='ArrowLeft'&&e.key!=='ArrowRight')return;
836 if(e.metaKey||e.ctrlKey||e.altKey)return;
837 const t=e.target;
838 if(t&&(t.tagName==='INPUT'||t.tagName==='TEXTAREA'||t.isContentEditable))return;
839 e.preventDefault();hideHint();
840 step(e.key==='ArrowRight'?'next':'prev');
841});
842document.getElementById('heroDown').onclick=()=>{
843 document.getElementById('about').scrollIntoView({behavior:'smooth',block:'start'});
844};
845
846/* --------------------------------------------------- loupe + controls */
847const loupe=document.getElementById('loupe');
848const lens=document.getElementById('loupeLens');
849const mag=document.getElementById('loupeMag');
850const zRead=document.getElementById('zRead');
851const loupeBtn=document.getElementById('loupeBtn');
852const zInBtn=document.getElementById('zIn'), zOutBtn=document.getElementById('zOut');
853const MAG=2.3;
854const DESK=getComputedStyle(document.documentElement).getPropertyValue('--paper').trim()||'#ece7dc';
855let loupeOn=true, lx=null, ly=null, lgrab=null, lTarget=null;
856
857function loupeSize(){return Math.round(Math.max(165,Math.min(262,book.clientWidth*0.235)));}
858/* the loupe's own coordinate space: stage pixels in live mode (it sits
859 outside the book's transform), book pixels otherwise */
860function bookBox(){
861 return {x:0,y:0,w:book.clientWidth,h:book.clientHeight};
862}
863/* park it on the desk at the lower right, half off the book */
864function restLoupe(){
865 const b=bookBox();
866 lx=b.x+b.w*0.88; ly=b.y+b.h*0.855;
867 placeLoupe();
868}
869/* The glass sits above the tilt, in the book's untransformed pixels, so the
870 lean of the page never nudges it. What the tilt does change is which part
871 of the paper is under the glass, and only the scale matters enough to
872 correct for: the book is drawn about its own centre. */
873const zoomWrap=document.getElementById('zoomWrap');
874const zoomInner=document.getElementById('zoomInner');
875/* mirror whatever the book is currently showing into the magnified copy */
876function syncZoomLayer(){
877 zoomInner.textContent='';
878 for(const c of book.children){
879 if(c.classList.contains('sb-zone'))continue; /* hit targets need no copy */
880 zoomInner.appendChild(c.cloneNode(true));
881 }
882}
883function placeLoupe(){
884 if(lx===null)return;
885 const B=bookBox(), bw=B.w, bh=B.h;
886 if(!bw)return;
887 const R=loupeSize()/2, bez=R*2*0.058;
888 loupe.style.setProperty('--lr',R*2+'px');
889 loupe.style.transform='translate3d('+(lx-R).toFixed(1)+'px,'+(ly-R).toFixed(1)+'px,0)';
890 if(loupeOn)loupe.classList.add('on');
891
892 /* where the paper's edges actually land once the book is scaled */
893 const z=view.z, cx=bw/2, cy=bh/2;
894 const x0=cx+(bw*.051-cx)*z, x1=cx+(bw*.949-cx)*z;
895 const y0=cy+(bh*.218-cy)*z, y1=cy+(bh*.782-cy)*z;
896 /* How far the glass's own centre is inside the paper. The copy fades out
897 as it wanders off the sheet, so you are left looking through plain
898 glass rather than at a sliver of page on flat desk. */
899 const nx=Math.max(x0,Math.min(lx,x1));
900 const ny=Math.max(y0,Math.min(ly,y1));
901 const inside=(lx>x0&&lx<x1&&ly>y0&&ly<y1)
902 ? Math.min(lx-x0, x1-lx, ly-y0, y1-ly)
903 : -Math.hypot(lx-nx,ly-ny);
904 const k=Math.max(0,Math.min(1,(inside+R*0.30)/(R*0.55)));
905
906 zoomWrap.style.opacity=(loupeOn?k:0).toFixed(3);
907 if(k<=0.002)return;
908 const r=(R-bez).toFixed(1);
909 const mask='radial-gradient(circle '+r+'px at '+lx.toFixed(1)+'px '+ly.toFixed(1)+'px,'
910 +'#000 calc(100% - 1px),transparent 100%)';
911 zoomWrap.style.webkitMaskImage=mask;
912 zoomWrap.style.maskImage=mask;
913 /* the page point beneath the glass, magnified about that same spot so the
914 lens keeps showing MAG times whatever is on screen */
915 const px=cx+(lx-cx)/z, py=cy+(ly-cy)/z, s=MAG*z;
916 zoomInner.style.transform='translate('+(lx-px*s).toFixed(1)+'px,'+(ly-py*s).toFixed(1)+'px) '
917 +'scale('+s.toFixed(4)+')';
918}
919/* the leaf shoves the glass aside as it sweeps past */
920function shoveLoupe(dir){
921 if(!loupeOn||lx===null||lgrab)return;
922 const b=bookBox();
923 /* which page point the glass covers, once the book's scale is undone */
924 const nx=(b.w/2+(lx-b.x-b.w/2)/view.z)/b.w, ny=(b.h/2+(ly-b.y-b.h/2)/view.z)/b.h;
925 if(nx<0.02||nx>0.98||ny<0.17||ny>0.83)return; /* already clear of the page */
926 lTarget={x:b.x+b.w*(dir==='next'?0.12:0.88), y:b.y+b.h*0.855};
927 kick();
928}
929function loupeEase(){
930 if(!lTarget)return false;
931 if(lgrab){lTarget=null;return false;}
932 const dx=lTarget.x-lx, dy=lTarget.y-ly;
933 if(Math.abs(dx)<0.5&&Math.abs(dy)<0.5){lx=lTarget.x;ly=lTarget.y;lTarget=null;placeLoupe();return false;}
934 lx+=dx*0.17;ly+=dy*0.17;placeLoupe();
935 return true;
936}
937loupe.addEventListener('pointerdown',e=>{
938 if(!loupeOn||e.button!==0)return;
939 e.preventDefault();e.stopPropagation(); /* never starts a page turn */
940 lTarget=null;
941 lgrab={cx:e.clientX,cy:e.clientY,lx0:lx,ly0:ly};
942 loupe.classList.add('held');
943 loupe.setPointerCapture(e.pointerId);
944 hideHint();
945});
946loupe.addEventListener('pointermove',e=>{
947 if(!lgrab)return;
948 const b=bookBox(), R=loupeSize()/2;
949 /* the glass carries none of the book's transform, so the cursor maps 1:1 */
950 lx=Math.max(b.x-R*0.7,Math.min(b.x+b.w+R*0.7, lgrab.lx0+(e.clientX-lgrab.cx)));
951 ly=Math.max(b.y-R*0.7,Math.min(b.y+b.h+R*1.0, lgrab.ly0+(e.clientY-lgrab.cy)));
952 placeLoupe();
953});
954function dropLoupe(){lgrab=null;loupe.classList.remove('held');}
955loupe.addEventListener('pointerup',dropLoupe);
956loupe.addEventListener('pointercancel',dropLoupe);
957loupeBtn.onclick=()=>{
958 loupeOn=!loupeOn;
959 loupeBtn.setAttribute('aria-pressed',String(loupeOn));
960 loupe.classList.toggle('on',loupeOn);
961 if(loupeOn&&lx===null)restLoupe();
962};
963addEventListener('resize',()=>{lx=null;restLoupe();});
964
965function syncZoom(){
966 zRead.textContent=Math.round(view.tz*100)+'%';
967 zOutBtn.disabled=view.tz<=ZOOM_MIN+0.001;
968 zInBtn.disabled=view.tz>=ZOOM_MAX-0.001;
969}
970zInBtn.onclick=()=>{setView(view.trx,view.try_,view.tz*1.16);hideHint();};
971zOutBtn.onclick=()=>{setView(view.trx,view.try_,view.tz/1.16);hideHint();};
972
973/* --------------------------------------------------------- the index */
974const plateList=document.getElementById('plateList');
975PAGES.forEach((p,i)=>{
976 const li=el('li');
977 const b=el('button','plate');
978 b.innerHTML='<span class="n">'+String(i+1).padStart(2,'0')+'</span>'+
979 '<span class="t"></span><span class="p"></span>';
980 b.querySelector('.t').textContent=p.title;
981 b.querySelector('.p').textContent=p.place;
982 b.onclick=()=>{goTo(i);document.getElementById('sketchbook').scrollIntoView({behavior:'smooth',block:'center'});};
983 li.appendChild(b);plateList.appendChild(li);
984});
985function marks(){
986 const cur=turn?turn.to:idx;
987 plateList.querySelectorAll('.plate').forEach((b,i)=>b.setAttribute('aria-current',i===cur?'true':'false'));
988}
989
990/* ---------------------------------------------------------- the riffle */
991let riffle=null,riffleAt=0,introOn=false;
992function endIntro(){
993 introOn=false;wrap.classList.remove('intro','b2');
994}
995function riffleStep(){
996 const s=riffle[riffleAt];
997 wrap.classList.toggle('b2',s.bell>0.55);
998 startTurn('next',0);
999 tweenTo(1,s.dur,()=>{
1000 idx=turn.to;turn=null;
1001 riffleAt++;
1002 if(introOn&&riffleAt<riffle.length){paint();riffleStep();}
1003 else{endIntro();paint();}
1004 });
1005}
1006function startIntro(){
1007 const coarse=matchMedia('(max-width: 640px), (pointer: coarse)').matches;
1008 if(coarse||REDUCED||Q.has('nointro')){idx=LAND;paint();return;}
1009 const steps=M+LAND;
1010 riffle=[];
1011 for(let r=0;r<steps;r++){
1012 const bell=Math.sin(Math.PI*(r/(steps-1)));
1013 riffle.push({bell:bell,dur:0.26-0.19*bell});
1014 }
1015 riffleAt=0;introOn=true;wrap.classList.add('intro');
1016 riffleStep();
1017}
1018
1019/* ------------------------------------------------------------- boot */
1020(async function boot(){
1021 idx=Q.has('shot')?(parseInt(Q.get('shot'),10)||0)%M:0;
1022 paint();applyView();
1023 await Promise.all(PAGES.map(p=>{
1024 const im=new __threeuiStorageImage();im.src=p.url;
1025 return im.decode?im.decode().catch(()=>{}):new Promise(r=>{im.onload=im.onerror=r});
1026 }));
1027 if(document.fonts&&document.fonts.ready)await document.fonts.ready.catch(()=>{});
1028 syncZoom();restLoupe();
1029 document.body.dataset.ready='1';
1030 if(Q.has('shot')){
1031 if(Q.has('t')){startTurn(Q.get('dir')||'next',parseFloat(Q.get('t')));}
1032 return;
1033 }
1034 setTimeout(startIntro,220);
1035})();
1036</script>
1037</body>
1038</html>
Keep looking