Skip to content
GitHub repository
Reference

API reference

Classes#

ClassDescription
ConicGradientAn angular ramp around a centre. On arcs it follows the arc. Create it with conic.
GradientBase class of all gradients. Stops are interpolated premultiplied (OKLab by default), baked into a shared half-float atlas and dithered when sampled, so gradients stay smooth without banding.
GradientAtlasAll gradient ramps live in one RGBA16F texture (one ramp per row), shared by every SilkGraphics. Half floats keep ~11 bits per channel so dark and low-alpha ramps don’t get quantised before the shader dithers them to the 8-bit framebuffer.
LinearGradientA straight ramp between two points. Create it with linear, vertical or horizontal.
PathGradientA ramp that follows a stroke from its first point (t = 0) to its last (t = 1). Create it with along.
RadialGradientA ramp from a centre outwards, optionally starting at an inner radius. Create it with radial.
SilkGeometryGeometry behind every SilkGraphics: one unit quad plus an interleaved instance buffer (40 floats per primitive). You rarely need it directly.
SilkGraphicsA PixiJS display object with a Graphics-like API. Every primitive is a signed distance field evaluated per pixel, so edges are smooth at any scale, rotation and device pixel ratio. Each object is one instanced draw call.
SpringDamped harmonic spring (semi-implicit Euler with fixed sub-steps). stiffness / damping follow the usual UI spring convention (e.g. 170 / 26).

Interfaces#

InterfaceDescription
AreaOptionsOptions of area(): monotone smoothing of the series and its sample spacing.
ConicGradientOptionsOptions of conic: stops plus centre, start angle and sweep.
FillStyleHow a fill is painted: a colour, a gradient, opacity and an optional gaussian blur for glows and soft shadows.
GradientOptionsOptions shared by every gradient: colour stops, interpolation space, easing, extend mode and units.
LinearGradientOptionsOptions of linear: stops plus the start and end points of the ramp.
PolylineOptionsOptions of polyline(): closed loops and monotone or Catmull-Rom smoothing of the points.
RadialGradientOptionsOptions of radial: stops plus centre, outer radius and inner radius.
SilkAppWhat createSilkApp returns: the Pixi application, its CSS size and resolution, and helpers to change or destroy it.
SilkAppOptionsOptions of createSilkApp: Pixi application options plus the element to fill, DPR limits and touch behaviour.
SilkGraphicsOptionsPer-object rendering settings of a SilkGraphics: dithering, anti-aliasing width and hairline threshold.
StrokeStyleHow a stroke is painted: width (or tapered widths), alignment, caps, dashes, plus everything in FillStyle.

Type Aliases#

Type AliasDescription
ColorSpaceColour space gradients are interpolated in: perceptual OKLab (default), linear light, or plain sRGB.
EasingHow the ramp moves between stops.
ExtendModeWhat a gradient does outside 0..1: hold the end colours (pad), tile (repeat) or mirror (reflect).
FillInputWhat fill() accepts: any Pixi colour, a gradient or a FillStyle.
GradientUnitsGradient coordinates: shape = fractions of each painted shape’s box, local = the graphics’ local units (one ramp across many shapes).
LineCapShape of the ends of open paths and of every dash: flat, round or square.
PointsInputPoints as a flat [x0, y0, x1, y1, ...] array, a typed array, or an array of { x, y } objects.
RGBAStraight (non-premultiplied) sRGB colour with alpha, all channels 0..1, as returned by parseColor.
StopInputA color stop: a bare color (stops are spread evenly), [offset, color], [offset, color, alpha] or { offset, color, alpha }.
StrokeInputWhat stroke() accepts: any Pixi colour, a gradient or a StrokeStyle.
Vec2A point [x, y]. In shape units, x and y are fractions of the painted shape’s box.

Variables#

VariableDescription
easeEasing curves for tweens (t from 0 to 1): inOutCubic, outCubic, inOutSine, outExpo.

Functions#

FunctionDescription
alongGradient that follows a stroke from its first point (t = 0) to its last (t = 1).
catmullRomCentripetal Catmull-Rom spline through the points (no cusps or self-loops).
conicConic (angular) gradient. On arcs and sectors it spans the arc by default, so a ring’s ramp always runs from its start cap to its end cap.
createSilkAppCreates a Pixi application tuned for smooth vector output:
dampExponential approach: moves current towards target. lambda is about 1/seconds, higher is snappier.
dampAngleDamped angle approach along the shortest path.
horizontalLeft-to-right linear gradient across the painted shape.
linearLinear gradient. from / to default to top and bottom of the shape’s box (units: 'shape').
linearToOklabConverts linear-light sRGB to OKLab (Björn Ottosson’s perceptual colour space), used to interpolate gradients evenly.
monotoneXMonotone cubic interpolation in x (Steffen’s method, same family as d3’s monotoneX). Never overshoots the data: peaks stay at the data points, flat runs stay flat. step is the target spacing of the output samples in local units.
oklabToLinearConverts OKLab back to linear-light sRGB. Out-of-gamut colours fall outside 0..1, so callers clamp.
parseColorAny Pixi ColorSource as straight sRGB [r, g, b, a] (0..1), with alpha multiplied in. Memoised.
radialRadial gradient from center (default the box centre) out to radius, optionally starting at innerRadius.
toFlatNormalises [x0, y0, x1, y1, ...] or [{x, y}, ...] into a flat number array.
verticalTop-to-bottom linear gradient across the painted shape.