ThorVG WebCanvas API - v1.1.4
    Preparing search index...

    Class RadialGradient

    Radial gradient for filling shapes

    // Basic radial gradient
    const gradient = new TVG.RadialGradient(200, 200, 100);
    gradient.addStop(0, [255, 255, 255, 255]) // White center
    .addStop(1, [100, 100, 255, 255]); // Blue edge

    const shape = new TVG.Shape();
    shape.appendCircle(200, 200, 100)
    .fillGradient(gradient);

    canvas.add(shape);
    // Radial gradient with focal point
    // Create gradient with offset focal point for lighting effect
    const gradient = new TVG.RadialGradient(
    200, 200, 100, // Center and radius
    170, 170, 0 // Focal point (offset)
    );
    gradient.addStop(0, [255, 255, 200, 255])
    .addStop(1, [255, 100, 100, 255]);

    const shape = new TVG.Shape();
    shape.appendCircle(200, 200, 100)
    .fillGradient(gradient);

    canvas.add(shape);

    Hierarchy (View Summary)

    • Fill
      • RadialGradient
    Index
    _filled: boolean = false
    _stops: ColorStopEntry[] = []
    • get ptr(): number

      Gets the WASM pointer for this object Returns 0 if object has been disposed (error handled by global handler)

      Returns number

    • get isDisposed(): boolean

      Check if this object has been disposed

      Returns boolean

    • Cleanup function to be implemented by subclasses

      Parameters

      • ptr: number

        The WASM pointer to clean up

      Returns void

    • Add a color stop to the gradient

      Parameters

      • offset: number

        Position of the stop (0.0 to 1.0)

      • color: ColorStop

        RGBA color [r, g, b, a] where each value is 0-255

      Returns this

    • Clear all pending color stops Use this to reset stops before adding new ones

      Returns this

      The Fill instance for method chaining

      const gradient = new TVG.LinearGradient(0, 0, 200, 0);
      gradient.addStop(0, [255, 0, 0, 255])
      .addStop(1, [0, 0, 255, 255]);

      // Change stops
      gradient.clearStops()
      .addStop(0, [0, 255, 0, 255])
      .addStop(1, [255, 255, 0, 255]);

      shape.fill(gradient);
    • Replace all color stops with new ones This is a convenience method that clears existing stops and adds new ones in one call

      Parameters

      • ...stops: [number, ColorStop][]

        Variable number of [offset, color] tuples

      Returns this

      The Fill instance for method chaining

      const gradient = new TVG.LinearGradient(0, 0, 200, 0);
      gradient.setStops(
      [0, [255, 0, 0, 255]], // Red at start
      [0.5, [255, 255, 0, 255]], // Yellow at middle
      [1, [0, 255, 0, 255]] // Green at end
      );

      shape.fill(gradient);

      // Later, completely replace stops
      gradient.setStops(
      [0, [0, 0, 255, 255]], // Blue at start
      [1, [255, 0, 255, 255]] // Magenta at end
      );

      shape.fill(gradient); // Re-apply with new stops
    • Apply collected color stops to the gradient ColorStop struct: {float offset, uint8_t r, g, b, a} = 8 bytes per stop

      Returns void

    • Build the gradient (apply all color stops) This should be called after all addStop() calls

      Returns this