Skip to content

Gradient

Overview

Abstract base type for LinearGradient and RadialGradient.

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class Gradient

import { Gradient } from 'scenerystack/scenery';

Constructor

new Gradient()

Instance Methods

addColorStop( ratio : number, color : TColor ) : this

Adds a color stop to the gradient.

Color stops should be added in order (monotonically increasing ratio values).

NOTE: Color stops should only be added before using the gradient as a fill/stroke. Adding stops afterwards will result in undefined behavior. TODO: Catch attempts to do the above. https://github.com/phetsims/scenery/issues/1581

@param ratio - Monotonically increasing value in the range of 0 to 1 @param color @returns - for chaining

createCanvasGradient() : CanvasGradient

Subtypes should return a fresh CanvasGradient type.

getSVGStops() : GradientStop[]

Returns stops suitable for direct SVG use.

invalidateCanvasGradient()

Forces a re-check of whether colors have changed, so that the Canvas gradient can be regenerated if necessary.

getCanvasStyle() : CanvasGradient

Returns an object that can be passed to a Canvas context's fillStyle or strokeStyle.

Instance Properties

stops : GradientStop[]

isGradient : boolean

Static Methods

colorToString( color : TColor ) : string

Returns the current value of the generally-allowed color types for Gradient, as a string.

Type GradientStop

import type { GradientStop } from 'scenerystack/scenery';

Source Code

See the source for Gradient.ts in the scenery repository.