src/swipl-devel/packages/xpce/man/refmanual/md/gradient.md

class gradient {#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.

Gradients live in the coordinate system of the graphical they fill — the same one the shape's own drawing commands use. Passing a gradient to a scrolled or transformed device therefore just works; the pattern scrolls and scales with the shape.

Two kinds are supported:

A gradient needs at least one stop to render anything visible; two stops give a two-colour transition; more stops give piecewise interpolation.

Example: a top-to-bottom yellow-to-red fill on a 100×60 box.

new(P, picture), send(P, open),
new(Chain, chain),
send(Chain, append, new(_, tuple(0.0, colour(yellow)))),
send(Chain, append, new(_, tuple(1.0, colour(red)))),
new(G, gradient(linear, point(0,0), point(0,60),
                @default, @default, Chain)),
send(P, display, new(B, box(100, 60)), point(20, 20)),
send(B, pen, 0),
send(B, fill, G).

Because a gradient is a data object rather than a graphical, it may be attached to as many shapes as desired. Two shapes sharing a gradient will each sample the pattern in their own coordinate space.

@see graphical<->fill_pattern @see colour @see box->fill

Instance variables {#class-gradient-instvars}

Send methods {#class-gradient-send}



Try the rswipl package in your browser

Any scripts or data that you put into this service are public.

rswipl documentation built on Sept. 26, 2026, 1:07 a.m.