# Class LinearGradient

java.lang.Object
com.codename1.ui.Gradient
com.codename1.ui.LinearGradient

All Implemented Interfaces:
  `Paint`

public final class LinearGradient extends Gradient
Multi-stop linear gradient at an arbitrary angle. Mirrors CSS `linear-gradient(<angle>, <stops>)`. Angle is in CSS degrees: 0 points up (toward the top edge), 90 right, 180 down, 270 left.

- ## Field Summary

  ### Fields inherited from class Gradient

  `CYCLE_NONE, CYCLE_REFLECT, CYCLE_REPEAT, KIND_CONIC, KIND_LINEAR, KIND_RADIAL`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LinearGradient(float angleDegrees, int[] colors, float[] positions)`
  Creates a linear gradient at the given angle with the given stops.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `computeEndpoints(int width, int height, float[] out)`
  Computes the endpoints of the gradient line for a rectangle of the given width / height (rect origin at (0,0)).
  `void`
  `computeShaderEndpoints(int width, int height, float[] out)`
  Computes shader-ready endpoints for native APIs like Android's `LinearGradient` and Java2D's `LinearGradientPaint`.
  `LinearGradient`
  `copy()`
  Returns a defensive deep copy.
  `float`
  `getAngleDegrees()`
  `byte`
  `getKind()`
  Returns one of `KIND_LINEAR`, `KIND_RADIAL`, `KIND_CONIC`.
  `float[]`
  `getNormalizedPositions()`
  Returns stop positions rescaled to `[0, 1]` within the `[first_stop, last_stop]` range of the original positions.
  `int`
  `sampleArgb(int px, int py, int width, int height)`
  Software-rasterizer hook used by the default port implementation when no native gradient shader is available.
  `LinearGradient`
  `setAngleDegrees(float angleDegrees)`

  ### Methods inherited from class Gradient

  `getCachedRaster, getColors, getCycleMethod, getPositions, invalidateRasterCache, paint, paint, parseCss, sampleStops, setCycleMethod`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### LinearGradient

    public LinearGradient(float angleDegrees, int[] colors, float[] positions)
    Creates a linear gradient at the given angle with the given stops.

- ## Method Details

  - ### getKind

    public byte getKind()
    Description copied from class: `Gradient`
    Returns one of `KIND_LINEAR`, `KIND_RADIAL`, `KIND_CONIC`.
    Specified by:
      `getKind` in class `Gradient`

  - ### getAngleDegrees

    public float getAngleDegrees()

  - ### setAngleDegrees

    public LinearGradient setAngleDegrees(float angleDegrees)

  - ### computeEndpoints

    public void computeEndpoints(int width, int height, float[] out)
    Computes the endpoints of the gradient line for a rectangle of the given width / height (rect origin at (0,0)). Output is x0,y0,x1,y1. These endpoints span the full bounding box; stop positions are interpreted relative to them.

  - ### computeShaderEndpoints

    public void computeShaderEndpoints(int width, int height, float[] out)

    Computes shader-ready endpoints for native APIs like Android's `LinearGradient` and Java2D's `LinearGradientPaint`. For NO_CYCLE this is the same as `computeEndpoints`. For REPEAT / REFLECT it clips the endpoint range to span exactly one stop-list period (from `getPositions()[0]` to `getPositions()[N-1]` of the original line) so the native shader's tile mode wraps the period across the rest of the bounding box - matching the CSS `repeating-linear-gradient` semantic.

    Use `getNormalizedPositions()` for the matching stop array when using these endpoints with REPEAT/REFLECT.

  - ### getNormalizedPositions

    public float[] getNormalizedPositions()
    Returns stop positions rescaled to `[0, 1]` within the `[first_stop, last_stop]` range of the original positions. For NO_CYCLE this is the same as `getPositions()`; for REPEAT/REFLECT it is the array to pass alongside `computeShaderEndpoints`.

  - ### sampleArgb

    public int sampleArgb(int px, int py, int width, int height)
    Description copied from class: `Gradient`
    Software-rasterizer hook used by the default port implementation when no native gradient shader is available. Samples an ARGB color for the pixel at (px, py) within a rectangle of the given width / height. Ports overriding `fillGradient` directly do not call this.
    Specified by:
      `sampleArgb` in class `Gradient`

  - ### copy

    public LinearGradient copy()
    Description copied from class: `Gradient`
    Returns a defensive deep copy. Implemented by each concrete subclass so async-paint queues can capture an immutable snapshot.
    Specified by:
      `copy` in class `Gradient`