Class RasterGradient

java.lang.Object
com.codename1.backend.image.RasterGradient
All Implemented Interfaces:
RasterPaint

public final class RasterGradient extends Object implements RasterPaint

A linear or radial color gradient for RasterGraphics.setPaint(RasterPaint).

Colors are interpolated per channel, not premultiplied, between stops at increasing fractions from 0 to 1. Before the first stop and after the last one the end colors extend ("pad").

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    getColor(double x, double y)
    Returns the gradient's color at a point.
    linear(double x1, double y1, double x2, double y2, float[] fractions, int[] colors)
    Creates a gradient along the line from (x1, y1) (fraction 0) to (x2, y2) (fraction 1).
    radial(double cx, double cy, double radius, float[] fractions, int[] colors)
    Creates a circular gradient from the center (fraction 0) to the circle of radius (fraction 1).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • linear

      public static RasterGradient linear(double x1, double y1, double x2, double y2, float[] fractions, int[] colors)

      Creates a gradient along the line from (x1, y1) (fraction 0) to (x2, y2) (fraction 1).

      Parameters
      • x1: start x
      • y1: start y
      • x2: end x
      • y2: end y
      • fractions: stop positions, 0 to 1, not decreasing
      • colors: ARGB color of each stop
      Returns

      the gradient

    • radial

      public static RasterGradient radial(double cx, double cy, double radius, float[] fractions, int[] colors)

      Creates a circular gradient from the center (fraction 0) to the circle of radius (fraction 1).

      Parameters
      • cx: center x
      • cy: center y
      • radius: radius, above zero
      • fractions: stop positions, 0 to 1, not decreasing
      • colors: ARGB color of each stop
      Returns

      the gradient

    • getColor

      public int getColor(double x, double y)

      Returns the gradient's color at a point.

      Parameters
      • x: user-space x
      • y: user-space y
      Returns

      the ARGB color

      Specified by:
      getColor in interface RasterPaint