an.stage.gradients#
Gradient fills on the stage: a Gradient drawn as an inline SVG texture.
The stage draws a gradient the way it already draws a glow (an#163): as ordinary
document content – a data: SVG texture under a content-addressed alias,
on an svg_sprite visual – not as a runtime feature. So runtime.js does
not change, staging skips the inline source, and the bytes of the texture are a
pure function of the gradient and its box.
Two boxes matter:
the box the sprite covers (a plane’s declared
size, or the fill span that covers the canvas at any camera position), andthe frame the gradient is laid out over (the declared
size, or the canvas): a gradient without a declared size is shaped by what the camera shows, and beyond the frame its end colours hold (SVG’sspreadMethodpad, CSS’s behaviour), so a pan never runs off the edge of the paint.
The SVG is rasterised at most GRADIENT_RASTER_MAX pixels on its longer
side and stretched to the box – a smooth ramp loses nothing to that, and a
4000-pixel backdrop does not cost a 64 MB texture.
>>> from an.paint import Gradient
>>> svg = gradient_svg(Gradient(stops=["#000", "#fff"]), box=(100.0, 50.0), frame=(100.0, 50.0))
>>> svg.startswith('<svg xmlns="http://www.w3.org/2000/svg" width="100" height="50"')
True
>>> 'x1="50" y1="0" x2="50" y2="50"' in svg # CSS's default: top to bottom
True
Module Attributes
The longest side, in texture pixels, a gradient is rasterised at. |
Functions
|
The SVG that paints |
|
|
|
A content-addressed texture alias: the same gradient, the same alias. |
- an.stage.gradients.GRADIENT_RASTER_MAX: int = 1024#
The longest side, in texture pixels, a gradient is rasterised at.
- an.stage.gradients.gradient_alias(prefix, src)[source]#
A content-addressed texture alias: the same gradient, the same alias.
- Return type:
>>> gradient_alias("glass.sky", "data:x") == gradient_alias("glass.sky", "data:x") True
- an.stage.gradients.gradient_src(svg)[source]#
svgas the inline (data:) texture source the runtime loads.- Return type:
- an.stage.gradients.gradient_svg(gradient, *, box, frame, raster_max=1024)[source]#
The SVG that paints
gradientoverbox, laid out on the centredframe.Coordinates are scene pixels (the
viewBox);width/heightare the raster size, at mostraster_maxon the longer side.- Return type:
>>> from an.paint import Gradient >>> svg = gradient_svg(Gradient(type="radial", stops=["#fff", "#000"]), ... box=(4000.0, 4000.0), frame=(1920.0, 1080.0)) >>> 'width="1024" height="1024"' in svg True >>> 'gradientTransform="translate(2000 2000) scale(960 540)"' in svg True