|

Initializers

Compositions that fill a fresh canvas, so a drawing never starts from blank paper. Each initializer rolls a plan, plain data: a background spec and a list of marks, each naming a registry tool with its values, colors, width, and path in world units. A fill’s radius rides its width (the contour is drawn at 1.3 times it), and the split initializer’s color regions ride the background spec, so a recording reproduces them with its clear.

public/lib/demo/initializers.js

Two executors run a plan. runInitializer({ stage, board }, plan) bakes it straight onto a board, for the initializer demos. The drawing tool runs one on every clear, picked at random from its config’s initializers list and rolled from the page’s own tool set, and feeds the marks through its cycle, so the result records, replays, and mirrors like anything drawn (the records carry initial: true, so a playback can place them instantly). The try-drawing demos use ['scatter'], the default; the Drawing Tool Demo and the packaging layer pick from all four.

Rolling uses Math.random; a host that needs determinism records what the marks drew. Where a roll’s preferred tool kind is missing from the page’s set, any tool stands in.

The initializers

  • scatterInit — the drawing tool's own start: a paper gradient and one to four strokes scattered with random stroke tools and palette colors, the first one long.
  • patternInit — a random stroke tool draws one narrow-lined composition in two alternating palette colors (stripes at a random angle, a grid, or wave rows), with even odds of a second composition overlapping the first.
  • splitInit — the canvas divided by a random straight line, each part divided again at even odds a few levels deep, every region filled with a flat palette color, and one to four random strokes on top. The division is a half-plane clip of the region's polygon through a point near its centroid.
  • fillsInit — one to three very big fills with random fill tools; each fill's spine runs from a point past one edge into the far half of the canvas, so it always crosses the midline without having to cover the center.

The demo harness

setupInitializerDemo(initialize) is what the initializer demos share: a stage, a board, and the corner button that runs the initializer again with a fresh palette and scheme.