VectorGradientBuilder
ClassA 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
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
| Parameter | Type | Description |
|---|---|---|
offset | number | The stop position (Number, finite, clamped to [0, 1]). |
color | vec4 | Normalized 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
Since
Lens Scripting Version 370
getTypeName()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
linear()
staticlinear(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
| Parameter | Type | Description |
|---|---|---|
start | vec2 | The gradient's start point (vec2), in composite coordinate space. |
end | vec2 | The gradient's end point (vec2), in composite coordinate space. |
Returns
VectorGradientBuilder
Since
Lens Scripting Version 370
radial()
staticradial(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
| Parameter | Type | Description |
|---|---|---|
center | vec2 | The gradient's center (vec2), in composite coordinate space. |
radius | number | The 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
| Parameter | Type | Description |
|---|---|---|
focalCenter | vec2 | The focal point (vec2), in composite coordinate space. |
focalRadius | number | The 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
| Parameter | Type | Description |
|---|---|---|
mode | SpreadMode | The spread mode. |
Returns
void
Since
Lens Scripting Version 370