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

    Class ConicGradientBeta

    Conic gradient for filling shapes

    The gradient color transitions by the angle measured around a center point, completing a full clockwise turn from the start angle.

    Spread options are ignored because the gradient always sweeps a full turn.

    // Color wheel
    const gradient = new TVG.ConicGradient(200, 200);
    gradient.addStop(0, [255, 0, 0, 255]) // Red
    .addStop(1 / 3, [0, 255, 0, 255]) // Green
    .addStop(2 / 3, [0, 0, 255, 255]) // Blue
    .addStop(1, [255, 0, 0, 255]); // Back to red for a seamless loop

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

    canvas.add(shape);
    // Sweep starting from 12 o'clock
    const gradient = new TVG.ConicGradient(200, 200, -90);
    gradient.addStop(0, [255, 255, 255, 0])
    .addStop(1, [0, 150, 255, 255]);

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

    canvas.add(shape);

    Hierarchy (View Summary)

    Index
    • Beta

      The gradient sweeps a full turn clockwise around the center (cx, cy), beginning at angle. Color stop offsets from 0 to 1 map clockwise over one full turn from angle.

      Parameters

      • cx: number

        The horizontal coordinate of the center of the gradient

      • cy: number

        The vertical coordinate of the center of the gradient

      • angle: number = 0

        The initial angle in degrees, measured clockwise from the 3 o'clock direction (positive x-axis). Default: 0

      Returns ConicGradient

    _filled: boolean = false
    _stops: ColorStopEntry[] = []
    • get ptr(): number
      Beta

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

      Returns number

    • get isDisposed(): boolean
      Beta

      Check if this object has been disposed

      Returns boolean

    • Beta

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

      Returns this

    • Beta

      Cleanup function to be implemented by subclasses

      Parameters

      • ptr: number

        The WASM pointer to clean up

      Returns void

    • Beta

      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

    • Beta

      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);
    • Beta

      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
    • Beta

      Apply collected color stops to the gradient ColorStop struct: {float offset, uint8_t r, g, b, a} = 8 bytes per stop

      Returns void