Skip to main content

VectorGradientBuilder

Class

A mutable builder for an immutable VectorGradient paint.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported — Available on SPECS only
  • SPECSFully supported
  • Camera Kit WebNot supported — Available on SPECS only
  • Camera Kit MobileNot supported — Available on SPECS only

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not supported — Available on SPECS only.

Since Lens Scripting v370

A mutable builder for an immutable VectorGradient paint. Start one with the VectorGradientBuilder.linear or VectorGradientBuilder.radial factory, add at least two color stops with VectorGradientBuilder#addColorStop, optionally set a focal circle (VectorGradientBuilder#setFocal, radial only) and a spread mode, then call VectorGradientBuilder#build to produce the gradient. Coordinates are native vec2 values in the consuming composite's coordinate space (the same space as path points); colors are normalized straight-alpha vec4 values. The builder remains usable after build().

Index

Example

// A linear gradient, reusable across multiple filled paths.
var gb = VectorGradientBuilder.linear(new vec2(0, 0), new vec2(512, 0));
gb.addColorStop(0.0, new vec4(0.92, 0.26, 0.21, 1.0));
gb.addColorStop(1.0, new vec4(0.13, 0.59, 0.95, 1.0));
gb.setSpread(VectorComposite.SpreadMode.Reflect);
var sunset = gb.build();

// A radial gradient with an off-center focal highlight.
var rb = VectorGradientBuilder.radial(new vec2(256, 256), 200);
rb.setFocal(new vec2(210, 210), 0);
rb.addColorStop(0.0, new vec4(1, 1, 1, 1));
rb.addColorStop(1.0, new vec4(0, 0, 0, 1));
var glow = rb.build();

Extends

Methods

addColorStop()

addColorStop(offset, color): void

SPECS

Adds a color stop at offset (a finite Number, clamped to [0, 1]) with color (a normalized straight-alpha RGBA vec4; components outside [0, 1] are clamped). Stops may be added in any order — VectorGradientBuilder#build sorts them ascending by offset (stably, so equal offsets keep insertion order). Throws if offset or any color component is not finite.

Parameters

ParameterTypeDescription
offsetnumberThe stop position (Number, finite, clamped to [0, 1]).
colorvec4Normalized RGBA color (vec4, each component clamped to [0, 1]).

Returns

void

Since

Lens Scripting Version 370


build()

build(): VectorGradient

SPECS

Validates the accumulated state and returns a new immutable VectorGradient. Throws if the builder does not have between 2 and 16 color stops. The stops are sorted ascending by offset (stably) in the returned gradient. The builder remains usable afterward; the returned gradient is an independent snapshot.

Returns

VectorGradient

Since

Lens Scripting Version 370


getTypeName()

static getTypeName(): TypeName<VectorGradientBuilder>

SPECS

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<VectorGradientBuilder>

Since

Lens Scripting Version 370

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


linear()

static linear(start, end): VectorGradientBuilder

SPECS

Creates a builder for a linear gradient whose color ramp runs from start (parameter 0) to end (parameter 1). Throws if start and end coincide, or if either coordinate is not finite.

Parameters

ParameterTypeDescription
startvec2The gradient's start point (vec2), in composite coordinate space.
endvec2The gradient's end point (vec2), in composite coordinate space.

Returns

VectorGradientBuilder

Since

Lens Scripting Version 370


radial()

static radial(center, radius): VectorGradientBuilder

SPECS

Creates a builder for a radial gradient centered at center with outer radius radius. Without a VectorGradientBuilder#setFocal call the gradient is concentric (focal point at the center, focal radius 0). Throws if radius is not greater than 0, or if center or radius is not finite.

Parameters

ParameterTypeDescription
centervec2The gradient's center (vec2), in composite coordinate space.
radiusnumberThe outer radius (Number, must be > 0).

Returns

VectorGradientBuilder

Since

Lens Scripting Version 370


setFocal()

setFocal(focalCenter, focalRadius): void

SPECS

Radial only: sets the focal circle for an off-center highlight. By default (no call) the gradient is concentric. Throws if called on a linear builder, if focalRadius is negative, or if focalCenter or focalRadius is not finite.

Parameters

ParameterTypeDescription
focalCentervec2The focal point (vec2), in composite coordinate space.
focalRadiusnumberThe focal radius (Number, must be >= 0).

Returns

void

Since

Lens Scripting Version 370


setSpread()

setSpread(mode): void

SPECS

Sets the VectorComposite.SpreadMode — how the gradient extends beyond its [0, 1] range. Defaults to VectorComposite.SpreadMode.Pad.

Parameters

ParameterTypeDescription
modeSpreadModeThe spread mode.

Returns

void

Since

Lens Scripting Version 370