Class Brush

A Brush holds color information and describes how to draw the inside of a Shape or the stroke of a shape or a TextBlock or the background of any GraphObject.

A Brush must not be modified once it has been assigned to a GraphObject, such as the Shape.fill or TextBlock.stroke or GraphObject.background. However, a Brush may be shared by multiple GraphObjects.

Constructor Summary Details

Name Description
Brush(type)

Construct a Brush class that holds the given color information.More...

Parameters:
{EnumValue|string=} type
Optional, one of the values Brush.Solid, Brush.Linear, Brush.Radial, Brush.Pattern, or a well-formed CSS string describing a solid color brush. No parameter defaults to a Brush.Solid with a color description of 'black'.

Properties Summary Details

Name, Value Type Description
color
{string}

Gets or sets the color of a solid Brush.

colorStops
{Map.}

Gets or sets a Map holding all of the color stops used in this gradient, where the key is a number, the fractional distance between zero and one (inclusive), and where the corresponding value is a color string.More...

Call addColorStop in order to add color stops to this brush. This property value may be null if no gradient stops have been defined.

end
{Spot}

Gets or sets the ending location for a linear or radial gradient.More... A Spot value specifies a relative point in the object's GraphObject.naturalBounds. This defaults to Spot.BottomCenter for linear gradients and Spot.Center for radial gradients.

endRadius
{number}

Gets or sets the radius of a radial brush at the end location.More... The default value is NaN.

pattern
{HTMLCanvasElement|HTMLImageElement}

Gets or sets the pattern of a brush of type Brush.Pattern.More... Must be a reference to an HTMLCanvasElement or HTMLImageElement.

start
{Spot}

Gets or sets the starting location for a linear or radial gradient.More... A Spot value specifies a relative point in the object's GraphObject.naturalBounds. This defaults to Spot.TopCenter for linear gradients and Spot.Center for radial gradients.

startRadius
{number}

Gets or sets the radius of a radial brush at the start location.More... This defaults to zero.

type
{EnumValue}

Gets or sets the type of brush.More... The value must be one of: Brush.Solid, Brush.Linear, Brush.Radial, Brush.Pattern. If the new value is a linear or radial brush type, and if the start or end spots are not specific spots, they are changed to be specific spots, depending on the type of brush.

Method Summary Details

Name, Return Type Description
addColorStop(loc, color)

Specify a particular color at a particular fraction of the distance.More... If the type is Brush.Solid, change the type to Brush.Linear. You should have a color stop at zero and a color stop at one. You should not have duplicate color stop values at the same fractional distance.

Parameters:
{number} loc
between zero and one, inclusive.
{string} color
copy()
{Brush}

Create a copy of this Brush, with the same values.

Returns:
{Brush}
<static>
Brush.randomColor(min, max)
{string}

This static function can be used to generate a random color.More...

Parameters:
{number=} min
a number between zero and 255, defaults to 128.
{number=} max
a number between zero and 255, defaults to 255.
Returns:
{string} a color value in # hexadecimal format.

Constants Summary Details

Name Description
Linear {EnumValue}

For linear gradient brushes, used as the value for Brush.type.

Pattern {EnumValue}

For pattern brushes, used as the value for Brush.type.

Radial {EnumValue}

For radial gradient brushes, used as the value for Brush.type.

Solid {EnumValue}

For simple, solid color brushes, used as the value for Brush.type.