A Colormap implemented using Catmull-Rom colour splines. The map has a variable number
of knots with a minimum of four. The first and last knots give the tangent at the end
of the spline, and colours are interpolated from the second to the second-last knots.
Each knot can be given a type of interpolation. These are:
- LINEAR - linear interpolation to next knot
- SPLINE - spline interpolation to next knot
- CONSTANT - no interpolation - the colour is constant to the next knot
- HUE_CW - interpolation of hue clockwise to next knot
- HUE_CCW - interpolation of hue counter-clockwise to next knot
CIRCLE_DOWN
public static final int CIRCLE_DOWN
Interpolate with a falling circle shape curve.
CIRCLE_UP
public static final int CIRCLE_UP
Interpolate with a rising circle shape curve.
CONSTANT
public static final int CONSTANT
Don't tnterpolate - just use the starting value.
HUE_CCW
public static final int HUE_CCW
Interpolate hue counter clockwise.
HUE_CW
public static final int HUE_CW
Interpolate hue clockwise.
LINEAR
public static final int LINEAR
Interpolate linearly.
RGB
public static final int RGB
Interpolate in RGB space.
SPLINE
public static final int SPLINE
Interpolate using a spline.
Gradient
public Gradient()
Construct a Gradient.
Gradient
public Gradient(int[] rgb)
Construct a Gradient with the given colors.
Gradient
public Gradient(int[] x,
int[] rgb)
Construct a Gradient with the given colors and knot positions.
x
- the knot positionsrgb
- the colors
Gradient
public Gradient(int[] x,
int[] rgb,
byte[] types)
Construct a Gradient with the given colors, knot positions and interpolation types.
x
- the knot positionsrgb
- the colorstypes
- interpolation types
addKnot
public void addKnot(int x,
int color,
int type)
Add a new knot.
x
- the knot positioncolor
- the colortype
- the knot type
copyTo
public void copyTo(Gradient g)
Copy one Gradient into another.
g
- the Gradient to copy into
getKnot
public int getKnot(int n)
Get a knot color.
getKnotBlend
public byte getKnotBlend(int n)
Get a knot blend type.
getKnotPosition
public int getKnotPosition(int n)
Get a knot position.
getKnotType
public int getKnotType(int n)
Get a knot type.
getNumKnots
public int getNumKnots()
Get the number of knots in the gradient.
knotAt
public int knotAt(int x)
Return the knot at a given position.
- the knot number, or 1 if no knot found
mutate
public void mutate(float amount)
Mutate the gradient.
amount
- the amount in the range zero to one
randomGradient
public static Gradient randomGradient()
Build a random gradient.
randomize
public void randomize()
Randomize the gradient.
removeKnot
public void removeKnot(int n)
Remove a knot.
setColor
public void setColor(int n,
int color)
Set a knot color.
- setColor in interface ArrayColormap
n
- the knot indexcolor
- the color
setKnot
public void setKnot(int n,
int color)
Set a knot color.
n
- the knot indexcolor
- the color
setKnotBlend
public void setKnotBlend(int n,
int type)
Set a knot blend type.
n
- the knot indextype
- the knot blend type
setKnotPosition
public void setKnotPosition(int n,
int x)
Set a knot position.
n
- the knot indexx
- the knot position
setKnotType
public void setKnotType(int n,
int type)
Set a knot type.
n
- the knot indextype
- the type
setKnots
public void setKnots(int[] x,
int[] rgb,
byte[] types)
Set the values of all the knots.
This version does not require the "extra" knots at -1 and 256
x
- the knot positionsrgb
- the knot colorstypes
- the knot types
setKnots
public void setKnots(int[] x,
int[] y,
byte[] types,
int offset,
int count)
Set the values of a set of knots.
x
- the knot positionsy
- the knot colorstypes
- the knot typesoffset
- the first knot to setcount
- the number of knots
splitSpan
public void splitSpan(int n)
Split a span into two by adding a knot in the middle.