Style

A style with a color, linear gradient, radial gradient, or image.

Constructor

new Style(coloropt, linear_gradientopt, radial_gradientopt, imageopt)

Creates a new Style with the given color, linear gradient, radial gradient, or image. It must have exactly one of these.

Parameters:
NameTypeAttributesDescription
colorColor | null<optional>

The color of the style, if provided.

linear_gradientLinearGradient | null<optional>

The linear gradient of the style, if provided.

radial_gradientRadialGradient | null<optional>

The radial gradient of the style, if provided.

imageImageBitmap | null<optional>

The image of the style, if provided.

Classes

Style

Members

color

Gets the Color of the style, if it's a color.

color

Sets the style to a Color.

image

Gets the ImageBitmap of the style, if it's an image.

image

Sets the style to an ImageBitmap.

linear_gradient

Gets the LinearGradient of the style, if it's a linear gradient.

linear_gradient

Sets the style to a LinearGradient.

radial_gradient

Gets the RadialGradient of the style, if it's a radial gradient.

radial_gradient

Sets the style to a RadialGradient.

Methods

clone() → {Style}

Clones the Style.

Returns:

The cloned style.

Type: 
Style

color_at(p) → {Color}

Gets the Color at a given point.

Parameters:
NameTypeDescription
pPoint2D

The x coordinate of the point.

Returns:

The color at the given point.

Type: 
Color

fade(amount) → {Style}

Fades the Style by a given amount.

Parameters:
NameTypeDescription
amountnumber

The amount to fade the style by.

Returns:

The faded style.

Type: 
Style

(static) default_style() → {Style}

Returns the default Style, which is a color with the default color.

Returns:

The default style.

Type: 
Style

(static) from_color(color) → {Style}

Creates a new Style with the given color.

Parameters:
NameTypeDescription
colorColor

The color of the style.

Returns:

A new style from the color.

Type: 
Style

(static) from_image(image) → {Style}

Creates a new Style with the given image.

Parameters:
NameTypeDescription
imageImageBitmap

The image of the style.

Returns:

A new style from the image.

Type: 
Style

(static) from_linear_gradient(gradient) → {Style}

Creates a new Style with the given linear gradient.

Parameters:
NameTypeDescription
gradientLinearGradient

The linear gradient of the style.

Returns:

A new style from the linear gradient.

Type: 
Style

(static) from_radial_gradient(gradient) → {Style}

Creates a new Style with the given radial gradient.

Parameters:
NameTypeDescription
gradientRadialGradient
Returns:

A new style from the radial gradient.

Type: 
Style

(static) lerp(style1, style2, t, xopt, yopt, widthopt, heightopt, data_widthopt, data_heightopt) → {Style}

Linearly interpolates between two Styles given a progress value.

Parameters:
NameTypeAttributesDescription
style1Style

The first style.

style2Style

The second style.

tnumber

The progress value.

xnumber | null<optional>

Top left x coordinate of the bitmap. Must be provided if both styles are images.

ynumber | null<optional>

Top left y coordinate of the bitmap. Must be provided if both styles are images.

widthnumber | null<optional>

Width of the bitmap. Must be provided if both styles are images.

heightnumber | null<optional>

Height of the bitmap. Must be provided if both styles are images.

data_widthnumber | null<optional>

Number of pixels in a row of the bitmap. Must be provided if both styles are different kinds of gradients or one of them is an image.

data_heightnumber | null<optional>

Number of pixels in a column of the bitmap. Must be provided if both styles are different kinds of gradients or one of them is an image.

Returns:

The interpolated style.

Type: 
Style