Class GradientPaint
java.lang.Object
com.codename1.art.ArtPaint
com.codename1.art.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intColors change with the angle around the center.static final intColors 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.static final intColors change along the line from start to end.static final intColors change from the focal point out to the circle.static final intPast the ends the end colors continue.static final intPast the ends the gradient repeats mirrored.static final intPast the ends the gradient repeats. -
Constructor Summary
ConstructorsConstructorDescriptionGradientPaint(int type, float[] positions, int[] colors) Creates a gradient. -
Method Summary
Modifier and TypeMethodDescriptionintcolorAt(double x, double y, double[] bbox) The color at a point of paint space.intcolorFor(double t) The color at offsettafter spreading.static GradientPaintconic(double cx, double cy, double startAngle, float[] positions, int[] colors) A conic gradient.copy()A deep copy.static GradientPaintdiamond(double cx, double cy, double r, float[] positions, int[] colors) A diamond gradient.int[]Stop colors, as a copy.doublegetFx()Focal x of a radial gradient.doublegetFy()Focal y of a radial gradient.float[]Stop offsets, as a copy.doubleRadius of a radial gradient.intOne of theSPREAD_constants.The gradient transform.intgetType()The gradient type.doublegetX1()First x.doublegetX2()Second x.doublegetY1()First y.doublegetY2()Second y.booleanTrue when coordinates are fractions of the shape's bounding box.static GradientPaintlinear(double x1, double y1, double x2, double y2, float[] positions, int[] colors) A linear gradient.static GradientPaintradial(double cx, double cy, double r, float[] positions, int[] colors) A radial gradient with its focus at the center.voidsetObjectBoundingBox(boolean objectBoundingBox) Sets whether coordinates are relative to the bounding box.voidsetPoints(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.voidsetRadial(double r, double fx, double fy) Sets the radius and focal point of a radial gradient.voidsetSpread(int spread) Sets the spread.voidsetStops(float[] positions, int[] colors) Replaces the stops.voidsetTransform(Matrix transform) Sets the gradient transform.Methods inherited from class ArtPaint
copyBase, getBlendMode, getOpacity, isEnabled, setBlendMode, setEnabled, setOpacity
-
Field Details
-
LINEAR
public static final int LINEARColors change along the line from start to end.- See Also:
-
RADIAL
public static final int RADIALColors change from the focal point out to the circle.- See Also:
-
CONIC
public static final int CONICColors change with the angle around the center.- See Also:
-
DIAMOND
public static final int DIAMONDColors 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.- See Also:
-
SPREAD_PAD
public static final int SPREAD_PADPast the ends the end colors continue.- See Also:
-
SPREAD_REFLECT
public static final int SPREAD_REFLECTPast the ends the gradient repeats mirrored.- See Also:
-
SPREAD_REPEAT
public static final int SPREAD_REPEATPast the ends the gradient repeats.- See Also:
-
-
Constructor Details
-
GradientPaint
public GradientPaint(int type, float[] positions, int[] colors) Creates a gradient.
Parameters
type:LINEAR,RADIAL,CONICorDIAMONDpositions: stop offsets from 0 to 1, ascendingcolors: one0xAARRGGBBcolor 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
x1: start xy1: start yx2: end xy2: end ypositions: stop offsetscolors: stop colors
-
radial
A radial gradient with its focus at the center.
Parameters
cx: center xcy: center yr: radiuspositions: stop offsetscolors: stop colors
-
diamond
public static GradientPaint diamond(double cx, double cy, double r, float[] positions, int[] colors) A diamond gradient.
Parameters
cx: center xcy: center yr: the distance from the center to each corner of the outermost bandpositions: stop offsetscolors: stop colors
-
conic
public static GradientPaint conic(double cx, double cy, double startAngle, float[] positions, int[] colors) A conic gradient.
Parameters
cx: center xcy: center ystartAngle: angle of the first stop in radians, clockwise from 3 o'clockpositions: stop offsetscolors: stop colors
-
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
x1: first xy1: first yx2: second xy2: second y
-
setRadial
public void setRadial(double r, double fx, double fy) Sets the radius and focal point of a radial gradient.
Parameters
r: radiusfx: focal xfy: 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
positions: offsetscolors: 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 theSPREAD_constants. -
setSpread
public void setSpread(int spread) Sets the spread.
Parameters
spread: one of theSPREAD_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
objectBoundingBox: true for fractions of the bounding box
-
getTransform
The gradient transform. -
setTransform
Sets the gradient transform.
Parameters
transform: applied to the gradient's coordinates
-
colorAt
public int colorAt(double x, double y, double[] bbox) Description copied from class:ArtPaintThe color at a point of paint space.
Parameters
x: x in the space of the shape that is paintedy: y in that spacebbox: the shape's bounding box asx, y, w, h, for paints relative to it
-
colorFor
public int colorFor(double t) The color at offsettafter spreading.
-