No. 36Shared canvasHover to hold · click to stepTap to stepdraw 4 · 304 × 224 · canvas 512 × 352
Rulers on ratchets, out onlySize a draw needsThe draw, from (0, 0)copyTo(), 1:1No. 36. I’ve built the shared canvas as a drafting board, in device pixels at 2×. The corner block is (0, 0), where the viewport and the scissor start, and the two rulers that ride out from it mark the canvas’s far edges. It is born at 300 × 150, like every canvas element. When a draw needs more room, a ruler clicks out until it fits, and its ratchet never lets it back, up to MAX_TEXTURE_SIZE. A toggle needs 268 × 224 with its 40 px bleed, so the height ruler moves; a 96 px drop needs 352 × 352, so both do; a 256 × 144 pane needs 512 × 288, so the width ruler does; a button at its 72 px minimum needs 304 × 224, which fits, so nothing moves. Every card seats against the corner block, and copyTo() lifts off exactly its w × h, 1:1. In the code the canvas takes its new size in one step; I’ve let the rulers click out a tooth at a time so you can watch it, and spaced the teeth and the dots 32 px apart.
A drafting board in device pixels. The canvas is born at 300 × 150, and its rulers ride out whenever a draw needs more room.
Drawn while the skill was being made, for a long article on rendering frosted panes in WebGL.