Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class GradientPaint
A linear, radial or conic gradient.
Coordinates are in the painted shape’s space, or relative to its bounding box (0 to 1)
when isObjectBoundingBox is true, as SVG’s gradientUnits allows. getTransform is
applied to the gradient before it is painted.
Fields
public static final int LINEAR = 0 | Colors change along the line from start to end. |
public static final int RADIAL = 1 | Colors change from the focal point out to the circle. |
public static final int CONIC = 2 | Colors change with the angle around the center. |
public static final int DIAMOND = 3 | Colors change with the distance from the center measured along both axes together, so the bands are squares turned 45 degrees: Photoshop’s and Figma’s diamond. |
public static final int SPREAD_PAD = 0 | Past the ends the end colors continue. |
public static final int SPREAD_REFLECT = 1 | Past the ends the gradient repeats mirrored. |
public static final int SPREAD_REPEAT = 2 | Past the ends the gradient repeats. |
Constructors
public GradientPaint(int type, float[] positions, int[] colors) | Creates a gradient. |
Methods
Inherited methods
Field details
LINEAR
public static final int LINEAR = 0Colors change along the line from start to end.
RADIAL
public static final int RADIAL = 1Colors change from the focal point out to the circle.
CONIC
public static final int CONIC = 2Colors change with the angle around the center.
DIAMOND
public static final int DIAMOND = 3Colors change with the distance from the center measured along both axes together,
so the bands are squares turned 45 degrees: Photoshop’s and Figma’s diamond.
SPREAD_PAD
public static final int SPREAD_PAD = 0Past the ends the end colors continue.
SPREAD_REFLECT
public static final int SPREAD_REFLECT = 1Past the ends the gradient repeats mirrored.
SPREAD_REPEAT
public static final int SPREAD_REPEAT = 2Past the ends the gradient repeats.
Constructor details
GradientPaint
public GradientPaint(int type, float[] positions, int[] colors)Creates a gradient.
Parameters
typeintLINEAR,RADIAL,CONICorDIAMONDpositionsfloat[]- stop offsets from 0 to 1, ascending
colorsint[]- one
0xAARRGGBBcolor per stop
Method details
linear
public static GradientPaint linear(double x1, double y1, double x2, double y2, float[] positions, int[] colors)A linear gradient.
Parameters
x1double- start x
y1double- start y
x2double- end x
y2double- end y
positionsfloat[]- stop offsets
colorsint[]- stop colors
radial
public static GradientPaint radial(double cx, double cy, double r, float[] positions, int[] colors)A radial gradient with its focus at the center.
Parameters
cxdouble- center x
cydouble- center y
rdouble- radius
positionsfloat[]- stop offsets
colorsint[]- stop colors
diamond
public static GradientPaint diamond(double cx, double cy, double r, float[] positions, int[] colors)A diamond gradient.
Parameters
cxdouble- center x
cydouble- center y
rdouble- the distance from the center to each corner of the outermost band
positionsfloat[]- stop offsets
colorsint[]- stop colors
conic
public static GradientPaint conic(double cx, double cy, double startAngle, float[] positions, int[] colors)A conic gradient.
Parameters
cxdouble- center x
cydouble- center y
startAngledouble- angle of the first stop in radians, clockwise from 3 o’clock
positionsfloat[]- stop offsets
colorsint[]- stop colors
copy
public ArtPaint copy()A deep copy.
setPoints
public void setPoints(double x1, double y1, double x2, double y2)Sets the defining points: start and end for linear, center (twice) for radial, center
and a point on the start ray for conic.
Parameters
x1double- first x
y1double- first y
x2double- second x
y2double- second y
setRadial
public void setRadial(double r, double fx, double fy)Sets the radius and focal point of a radial gradient.
Parameters
rdouble- radius
fxdouble- focal x
fydouble- focal y
getType
public int getType()The gradient type.
getPositions
public float[] getPositions()Stop offsets, as a copy.
getColors
public int[] getColors()Stop colors, as a copy.
setStops
public void setStops(float[] positions, int[] colors)Replaces the stops.
Parameters
positionsfloat[]- offsets
colorsint[]- colors, one per offset
getX1
public double getX1()First x.
getY1
public double getY1()First y.
getX2
public double getX2()Second x.
getY2
public double getY2()Second y.
getRadius
public double getRadius()Radius of a radial gradient.
getFx
public double getFx()Focal x of a radial gradient.
getFy
public double getFy()Focal y of a radial gradient.
getSpread
public int getSpread()One of the
SPREAD_ constants.setSpread
public void setSpread(int spread)Sets the spread.
Parameters
spreadint- one of the
SPREAD_constants
isObjectBoundingBox
public boolean isObjectBoundingBox()True when coordinates are fractions of the shape’s bounding box.
setObjectBoundingBox
public void setObjectBoundingBox(boolean objectBoundingBox)Sets whether coordinates are relative to the bounding box.
Parameters
objectBoundingBoxboolean- true for fractions of the bounding box
getTransform
public Matrix getTransform()The gradient transform.
setTransform
public void setTransform(Matrix transform)Sets the gradient transform.
Parameters
transformMatrix- applied to the gradient’s coordinates
colorAt
public int colorAt(double x, double y, double[] bbox)The color at a point of paint space.
Parameters
xdouble- x in the space of the shape that is painted
ydouble- y in that space
bboxdouble[]- the shape’s bounding box as
x, y, w, h, for paints relative to it
colorFor
public int colorFor(double t)The color at offset
t after spreading.