1.78 class gradient

A gradient describes a linear or radial colour transition and can be used as the fill_pattern of any graphical that accepts a colour fill. The renderer draws the shape's outline as usual and fills it by sampling the gradient across the shape's area.

The points and radii of a gradient are interpreted according to gradient<-units:

1.78.1 Instance variables

gradient <- kind: {linear,radial}
Whether the gradient interpolates along a straight axis (linear) or between two circles (radial). Fixed at construction — build a fresh gradient to change kind.
gradient <- p0: point
Start point of the axis (linear) or centre of the start-circle (radial).
gradient <- p1: point
End point of the axis (linear) or centre of the end-circle (radial). For an axis-aligned linear gradient set gradient<-p0 and gradient<-p1 to the two corners of the shape; the perpendicular component is unused.
gradient <- r0: num*
Radius of the start-circle for a radial gradient. @nil (the default for a linear gradient) is treated as zero at draw time.
gradient <- r1: num*
Radius of the end-circle for a radial gradient. @nil (the default for a linear gradient) is treated as zero at draw time.
gradient <-> extend: {none,pad,repeat,reflect}
What is painted beyond the first and last stop: nothing (none), the colour of the nearest stop (pad), the gradient repeated (repeat), or repeated and mirrored every other time (reflect).

Defaults: pad

gradient <-> units: {user,bounding_box}
Whether gradient<-p0, gradient<-p1, gradient<-r0 and gradient<-r1 are device coordinates or fractions of the box around the shape being filled. See the class description.

Defaults: user

gradient <- stops: chain
Chain of tuple(fraction, colour) — the colour stops. Fractions are numbers in 0..1 (values outside are silently clamped by the renderer); the chain need not be sorted but the visual result depends on stop order for repeated fractions. Empty chains render as fully transparent.

1.78.2 Send methods

gradient ->initialise: kind={linear,radial}, p0=point, p1=point, r0=[num]*, r1=[num]*, stops=[chain], extend=[{none,pad,repeat,reflect}], units=[{user,bounding_box}]
Create the gradient. r0 and r1 are only meaningful when kind is radial; pass @default for a linear gradient and they are stored as @nil. If stops is @default an empty chain is created and stops must be added later with gradient->add_stop or gradient->stops.

See the class introduction for a runnable example.

gradient ->add_stop: fraction=num, colour=colour
Append tuple(fraction, colour) to gradient<-stops. Convenience wrapper equivalent to
send(G?stops, append, new(_, tuple(F, C)))

for the common incremental-build pattern.

gradient ->stops: chain
Replace the colour-stops chain wholesale. The elements should be tuple(fraction, colour) objects; the renderer skips anything else silently.