Skip to content

v2.5.0

Choose a tag to compare

@github-actions github-actions released this 02 Aug 15:51
· 16 commits to main since this release

Polar coordinates, on every effect

polar reads the field round a centre rather than straight across the canvas: one axis of the field becomes the angle about a point, the other the distance from it. The rain falls outwards from the middle of the page, the ridges stack into rings, the tunnel comes back round on itself.

createRainBackground(canvas, { polar: true });

createRidgesBackground(canvas, {
  polar: { turns: 3, centre: [0.5, 0], radius: 1.2 },
});

It bends the lookup rather than the field. Every effect goes on drawing its rectangle exactly as before and only the reading of it changes, which is why one option covers all seven and no effect had to learn anything.

Settings, all optional - true takes the defaults:

  • centre - the point it turns about, in fractions of the canvas. Outside 0..1 gives a fan rather than a wheel, and takes the sparkle at the middle off screen with it.
  • turns - copies of the field in one revolution. Keep it whole.
  • rotate - turns the picture clockwise.
  • radius - how far out the field reaches. 1 is exactly to the corners.
  • seam - 'mirror' folds the join away and is the default; 'wrap' keeps the field the right way round and shows it.
  • angleAxis - which axis carries the angle. 'x' sends the field's rows out as rings, 'y' its columns as spokes.

A press or drag is bent through the same transform, so an effect is still disturbed where it looks like it should be.

Two things worth knowing before turning it on. The centre is where the technique is weakest: one pixel there covers every angle at once, so the innermost cells read as a sparkle however fine the field is - move centre off the canvas to avoid it. And a polar lookup is not separable the way the plain one is, so it costs a table of two floats per rendered pixel, rebuilt on resize; about 1.3 MB at the default maxPixels. The frame itself costs what it did before.

If you use the middle layer

CommonBackgroundOptions has gained a polar field. Callers of mountBackground that hand-build a complete options object need to add it - spread COMMON_BACKGROUND_DEFAULTS and it is there. Everything that goes through createSmokeBackground and its six siblings takes a partial and is unaffected.

Also

  • The bundle claim is re-measured at 17.9 kB, up from 17.1 - the polar table's code is the difference. It is now pinned to a reproducible command rather than to history.
  • The demo has a Polar button and five dials beside the shading ones.