Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class RasterGradient

  1. Object
  2. RasterGradient

ImplementsRasterPaint

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”).

Methods

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).
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).
public int getColor(double x, double y)Returns the gradient’s color at a point.

Inherited methods

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 double
start x
y1 double
start y
x2 double
end x
y2 double
end y
fractions float[]
stop positions, 0 to 1, not decreasing
colors int[]
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 double
center x
cy double
center y
radius double
radius, above zero
fractions float[]
stop positions, 0 to 1, not decreasing
colors int[]
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 double
user-space x
y double
user-space y

Returns

the ARGB color