@@ -13,7 +13,8 @@ const HEIGHT = 7 + TOP + BOTTOM
1313
1414// Phase budgets in milliseconds; each phase's moves share its budget in proportion to length.
1515const PHASES = { metrics : 420 , grids : 620 , outlines : 820 , fill : 760 , shade : 380 }
16- const SETTLE = 220
16+ // After the last move the plot settles: the pen, readout and counter fade out and the guides dim.
17+ const SETTLE = 360
1718// The shade: the ink at the page's paper shade opacity.
1819const SHADE_ALPHA = 0.22
1920
@@ -170,7 +171,9 @@ export function CoverTitle() {
170171 let md = 16
171172 let dpr = 1
172173 let palette : Palette = { ink : "#141414" , blue : "#3b5cf6" , faint : "#bbb" }
173- let started : number | undefined
174+ let elapsed = reduced ? END : 0
175+ let last : number | undefined
176+ let played = false
174177 let frame = 0
175178
176179 const layout = ( ) => {
@@ -226,14 +229,14 @@ export function CoverTitle() {
226229 for ( const [ col , row ] of buildOrder ( WORD [ letter ] as Letter ) ) context . fillRect ( X ( letter * 5 + col ) , Y ( row ) , md , md )
227230 }
228231
229- const ticks = ( letter : number ) => {
232+ const ticks = ( letter : number , label : boolean ) => {
230233 const y = Y ( 7 ) + Math . round ( md * 0.55 )
231234 context . fillRect ( X ( letter * 5 ) , y , X ( letter * 5 + 4 ) - X ( letter * 5 ) , 1 )
232235 for ( let col = 0 ; col <= 4 ; col ++ ) {
233236 const x = Math . min ( X ( letter * 5 + col ) , X ( letter * 5 + 4 ) - 1 )
234237 context . fillRect ( x , y - Math . round ( md * 0.18 ) , 1 , Math . round ( md * 0.36 ) + 1 )
235238 }
236- context . fillText ( "4 × 120u" , X ( letter * 5 ) , y + Math . round ( md * 0.25 ) + 10 * dpr )
239+ if ( label ) context . fillText ( "4 × 120u" , X ( letter * 5 ) , y + Math . round ( md * 0.25 ) + 10 * dpr )
237240 }
238241
239242 const registration = ( ) => {
@@ -255,13 +258,17 @@ export function CoverTitle() {
255258 }
256259
257260 const draw = ( t : number ) => {
258- const done = t >= END
261+ // 0 while plotting, easing to 1 over the settle (an ease-out quint), so nothing snaps at the end.
262+ const settle = 1 - ( 1 - Math . min ( 1 , Math . max ( 0 , ( t - program . end ) / SETTLE ) ) ) ** 5
263+ const fade = ( to : number ) => 1 + ( to - 1 ) * settle
259264 context . clearRect ( 0 , 0 , canvas . width , canvas . height )
260265 context . font = `${ 10 * dpr } px "OpenTUI Mono", "OpenTUI Mono Menlo", ui-monospace, monospace`
261266 context . textBaseline = "alphabetic"
267+ // On a narrow canvas the module label is wider than a letter, so only the first letter carries it.
268+ const everyLabel = context . measureText ( "4 × 120u" ) . width + 4 * dpr <= 5 * md
262269
263270 // Registration marks: always there, faint once the plot is done.
264- context . globalAlpha = done ? 0.5 : 1
271+ context . globalAlpha = fade ( 0.5 )
265272 context . fillStyle = palette . blue
266273 registration ( )
267274 context . globalAlpha = 1
@@ -282,18 +289,18 @@ export function CoverTitle() {
282289 ]
283290 if ( move . kind === "metric" || move . kind === "grid" || move . kind === "outline" ) {
284291 context . fillStyle = move . kind === "outline" ? palette . blue : palette . faint
285- context . globalAlpha = done && move . kind !== "outline" ? 0.55 : 1
286- // Outlines vanish under the ink once a letter is filled; the grid and metrics stay faint.
287- if ( ! ( done && move . kind === "outline" ) ) hairline ( move . from , move . to , progress )
292+ // Outlines fade under the ink once the plot is done; the grid and metrics stay faint.
293+ context . globalAlpha = fade ( move . kind === "outline" ? 0 : 0.55 )
294+ hairline ( move . from , move . to , progress )
288295 context . globalAlpha = 1
289296 segments += progress === 1 ? 1 : 0
290297 travelled += length ( move ) * progress
291298 pen = { at, down : true }
292299 }
293300 if ( move . kind === "travel" ) {
294- if ( ! done && move . phase === phase ) {
301+ if ( move . phase === phase && settle < 1 ) {
295302 context . fillStyle = palette . blue
296- context . globalAlpha = 0.45
303+ context . globalAlpha = 0.45 * fade ( 0 )
297304 hairline ( move . from , move . to , progress , true )
298305 context . globalAlpha = 1
299306 }
@@ -308,8 +315,8 @@ export function CoverTitle() {
308315 if ( progress === 1 ) {
309316 filled . add ( move . letter )
310317 context . fillStyle = palette . blue
311- context . globalAlpha = done ? 0.6 : 1
312- ticks ( move . letter )
318+ context . globalAlpha = fade ( 0.6 )
319+ ticks ( move . letter , everyLabel || move . letter === 0 )
313320 context . globalAlpha = 1
314321 } else if ( shown > 0 ) {
315322 const [ col , row ] = order [ shown - 1 ]
@@ -334,7 +341,8 @@ export function CoverTitle() {
334341 context . fillStyle = palette . ink
335342 for ( const letter of filled ) fillLetter ( letter )
336343
337- if ( done || ! pen ) return
344+ if ( settle === 1 || ! pen ) return
345+ context . globalAlpha = fade ( 0 )
338346 // The pen: a filled square when down, an open one when up; its position in font units beside it.
339347 const px = X ( pen . at [ 0 ] )
340348 const py = Y ( pen . at [ 1 ] )
@@ -361,32 +369,50 @@ export function CoverTitle() {
361369 canvas . height - Math . round ( md * 0.35 ) ,
362370 )
363371 context . textAlign = "left"
372+ context . globalAlpha = 1
364373 }
365374
375+ // The plot's own clock: it advances only while frames run, so pausing off screen resumes in place.
366376 const tick = ( now : number ) => {
367- started ??= now
368- const t = now - started
369- draw ( t )
370- frame = t < END ? requestAnimationFrame ( tick ) : 0
377+ // A long gap (a background tab) resumes where it left off instead of skipping ahead.
378+ elapsed += last === undefined ? 0 : Math . min ( now - last , 100 )
379+ last = now
380+ draw ( elapsed )
381+ frame = elapsed < END ? requestAnimationFrame ( tick ) : 0
382+ }
383+ const resume = ( ) => {
384+ if ( reduced || frame || elapsed >= END ) return
385+ last = undefined
386+ frame = requestAnimationFrame ( tick )
371387 }
372388 const play = ( ) => {
373389 if ( reduced ) return
374390 cancelAnimationFrame ( frame )
375- started = undefined
376- frame = requestAnimationFrame ( tick )
391+ frame = 0
392+ played = true
393+ elapsed = 0
394+ resume ( )
377395 }
378396
379397 layout ( )
380- draw ( reduced ? END : 0 )
398+ draw ( elapsed )
399+ // The readout and labels are canvas text: start once the mono font is in, so they don't swap faces mid-plot.
400+ const fontReady = document . fonts . load ( `${ 10 * dpr } px "OpenTUI Mono"` ) . catch ( ( ) => undefined )
381401
402+ // Starts once most of the title is in view, and pauses whenever it leaves the screen.
382403 const observer = new IntersectionObserver (
383404 ( [ entry ] ) => {
384- if ( ! entry . isIntersecting ) return
385- observer . disconnect ( )
386- if ( reduced ) return draw ( END )
387- play ( )
405+ if ( ! entry . isIntersecting ) {
406+ cancelAnimationFrame ( frame )
407+ frame = 0
408+ return
409+ }
410+ if ( played ) return resume ( )
411+ if ( entry . intersectionRatio < 0.6 ) return
412+ played = true
413+ void fontReady . then ( play )
388414 } ,
389- { threshold : 0.6 } ,
415+ { threshold : [ 0 , 0.6 ] } ,
390416 )
391417 observer . observe ( root )
392418 root . addEventListener ( "click" , play )
@@ -396,13 +422,13 @@ export function CoverTitle() {
396422 if ( root . clientWidth === width ) return
397423 width = root . clientWidth
398424 layout ( )
399- if ( ! frame ) draw ( END )
425+ if ( ! frame ) draw ( elapsed )
400426 } )
401427 resize . observe ( root )
402428
403429 const repaint = ( ) => {
404430 layout ( )
405- if ( ! frame ) draw ( END )
431+ if ( ! frame ) draw ( elapsed )
406432 }
407433 const site = root . closest ( "[data-site]" )
408434 const themeObserver = new MutationObserver ( repaint )
0 commit comments