NAME

Prima::Drawable::Gradient - gradient fills for primitives

DESCRIPTION

Prima offers simple gradient services to draw gradually changing colors. A gradient is made by setting at least two colors and optionally a set of points that, when projected, generate the transition curve between the colors.

The module augments the Prima::Drawable drawing functionality by adding the new_gradient function.

SYNOPSIS

$canvas-> new_gradient(
	palette => [ cl::White, cl::Blue, cl::White ],
)-> sector(50,50,100,100,0,360);

API

Methods

clone %OPTIONS

Creates a new gradient object with %OPTIONS replaced.

new $CANVAS, %OPTIONS

Creates a new gradient object. The following %OPTIONS are available:

dither BOOLEAN = 0

When set, applies not only gradient colors but also different fill patterns to create an even smoother transition effect between adjacent colors. Works significantly slower.

palette @COLORS

Each color is a cl:: value. The gradient is calculated as a polyline where each of its vertices corresponds to a certain blend between two adjacent colors in the palette. F.ex. the simplest palette going from cl::White to cl::Black over a transition line 0..1 (default), produces a pure white color at the start and a pure black color at the end, with all available shades of gray in between.

poly @VERTICES

A set of 2-integer polyline vertices where the first integer is a coordinate (x, y, or whatever is required by the drawing primitive) between 0 and 1, and the second is the color blend value between 0 and 1.

Default: ((0,0),(1,1))

spline \@VERTICES, %OPTIONS

Serving the same purpose as the poly option but the vertices are projected first to a B-spline curve using render_spline and %OPTIONS. The resulting polyline is treated as poly.

vertical BOOLEAN

Only used in the bar primitive, to set the gradient direction.

widgetClass INTEGER

Points to the widget class to resolve generic colors like cl::Back that may differ between widget classes.

See also: bar, stripes .

bar X1, Y1, X2, Y2, VERTICAL = 0

Draws a filled rectangle with (X1,Y1) - (X2,Y2) extents

Context used: fillPattern, rop, rop2

colors BREADTH

Returns a list of gradient colors for each step from 1 to BREADTH. When dither is set, each color is an array of three items, - the two adjacent colors and an integer value between 0 and 63 that reflects the amount of blending needed between the colors.

ellipse X, Y, DIAM_X, DIAM_Y

Draws a filled ellipse with the center in (X,Y) and diameters (DIAM_X,DIAM_Y)

Context used: fillPattern, rop, rop2

sector X, Y, DIAM_X, DIAM_Y, START_ANGLE, END_ANGLE

Draws a filled sector with the center in (X,Y) and diameters (DIAM_X,DIAM_Y) from START_ANGLE to END_ANGLE

Context used: fillPattern, rop, rop2

stripes BREADTH

Returns an array consisting of integer pairs, where the first one is a color value, and the second is the breadth of the color strip. bar uses this information to draw a gradient fill, where each color strip is drawn with its own color. Can be used for implementing other gradient-aware primitives (see examples/f_fill.pl )

AUTHOR

Dmitry Karasik, <dmitry@karasik.eu.org>.

SEE ALSO

Prima::Drawable, examples/f_fill.pl, examples/gradient.pl