Class Gradient

All Implemented Interfaces:
Colormap, Cloneable

public class Gradient extends ArrayColormap implements Cloneable
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
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Interpolate with a falling circle shape curve.
    static final int
    Interpolate with a rising circle shape curve.
    static final int
    Don't tnterpolate - just use the starting value.
    static final int
    Interpolate hue counter clockwise.
    static final int
    Interpolate hue clockwise.
    static final int
    Interpolate linearly.
    static final int
    Interpolate in RGB space.
    static final int
    Interpolate using a spline.

    Fields inherited from class com.jhlabs.image.ArrayColormap

    map
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a Gradient.
    Gradient(int[] rgb)
    Construct a Gradient with the given colors.
    Gradient(int[] x, int[] rgb)
    Construct a Gradient with the given colors and knot positions.
    Gradient(int[] x, int[] rgb, byte[] types)
    Construct a Gradient with the given colors, knot positions and interpolation types.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addKnot(int x, int color, int type)
    Add a new knot.
     
    void
    Copy one Gradient into another.
    int
    getKnot(int n)
    Get a knot color.
    byte
    getKnotBlend(int n)
    Get a knot blend type.
    int
    Get a knot position.
    int
    getKnotType(int n)
    Get a knot type.
    int
    Get the number of knots in the gradient.
    int
    knotAt(int x)
    Return the knot at a given position.
    void
    mutate(float amount)
    Mutate the gradient.
    static Gradient
    Build a random gradient.
    void
    Randomize the gradient.
    void
    removeKnot(int n)
    Remove a knot.
    void
    setColor(int n, int color)
    Set a knot color.
    void
    setKnot(int n, int color)
    Set a knot color.
    void
    setKnotBlend(int n, int type)
    Set a knot blend type.
    void
    setKnotPosition(int n, int x)
    Set a knot position.
    void
    setKnots(int[] x, int[] rgb, byte[] types)
    Set the values of all the knots.
    void
    setKnots(int[] x, int[] y, byte[] types, int offset, int count)
    Set the values of a set of knots.
    void
    setKnotType(int n, int type)
    Set a knot type.
    void
    splitSpan(int n)
    Split a span into two by adding a knot in the middle.

    Methods inherited from class com.jhlabs.image.ArrayColormap

    getColor, getMap, setColorInterpolated, setColorRange, setColorRange, setMap

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • RGB

      public static final int RGB
      Interpolate in RGB space.
      See Also:
    • HUE_CW

      public static final int HUE_CW
      Interpolate hue clockwise.
      See Also:
    • HUE_CCW

      public static final int HUE_CCW
      Interpolate hue counter clockwise.
      See Also:
    • LINEAR

      public static final int LINEAR
      Interpolate linearly.
      See Also:
    • SPLINE

      public static final int SPLINE
      Interpolate using a spline.
      See Also:
    • CIRCLE_UP

      public static final int CIRCLE_UP
      Interpolate with a rising circle shape curve.
      See Also:
    • CIRCLE_DOWN

      public static final int CIRCLE_DOWN
      Interpolate with a falling circle shape curve.
      See Also:
    • CONSTANT

      public static final int CONSTANT
      Don't tnterpolate - just use the starting value.
      See Also:
  • Constructor Details

    • Gradient

      public Gradient()
      Construct a Gradient.
    • Gradient

      public Gradient(int[] rgb)
      Construct a Gradient with the given colors.
      Parameters:
      rgb - the colors
    • Gradient

      public Gradient(int[] x, int[] rgb)
      Construct a Gradient with the given colors and knot positions.
      Parameters:
      x - the knot positions
      rgb - the colors
    • Gradient

      public Gradient(int[] x, int[] rgb, byte[] types)
      Construct a Gradient with the given colors, knot positions and interpolation types.
      Parameters:
      x - the knot positions
      rgb - the colors
      types - interpolation types
  • Method Details

    • clone

      public Object clone()
      Overrides:
      clone in class ArrayColormap
    • copyTo

      public void copyTo(Gradient g)
      Copy one Gradient into another.
      Parameters:
      g - the Gradient to copy into
    • setColor

      public void setColor(int n, int color)
      Set a knot color.
      Overrides:
      setColor in class ArrayColormap
      Parameters:
      n - the knot index
      color - the color
      See Also:
    • getNumKnots

      public int getNumKnots()
      Get the number of knots in the gradient.
      Returns:
      the number of knots.
    • setKnot

      public void setKnot(int n, int color)
      Set a knot color.
      Parameters:
      n - the knot index
      color - the color
      See Also:
    • getKnot

      public int getKnot(int n)
      Get a knot color.
      Parameters:
      n - the knot index
      Returns:
      the knot color
      See Also:
    • setKnotType

      public void setKnotType(int n, int type)
      Set a knot type.
      Parameters:
      n - the knot index
      type - the type
      See Also:
    • getKnotType

      public int getKnotType(int n)
      Get a knot type.
      Parameters:
      n - the knot index
      Returns:
      the knot type
      See Also:
    • setKnotBlend

      public void setKnotBlend(int n, int type)
      Set a knot blend type.
      Parameters:
      n - the knot index
      type - the knot blend type
      See Also:
    • getKnotBlend

      public byte getKnotBlend(int n)
      Get a knot blend type.
      Parameters:
      n - the knot index
      Returns:
      the knot blend type
      See Also:
    • addKnot

      public void addKnot(int x, int color, int type)
      Add a new knot.
      Parameters:
      x - the knot position
      color - the color
      type - the knot type
      See Also:
    • removeKnot

      public void removeKnot(int n)
      Remove a knot.
      Parameters:
      n - the knot index
      See Also:
    • 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
      Parameters:
      x - the knot positions
      rgb - the knot colors
      types - 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.
      Parameters:
      x - the knot positions
      y - the knot colors
      types - the knot types
      offset - the first knot to set
      count - the number of knots
    • splitSpan

      public void splitSpan(int n)
      Split a span into two by adding a knot in the middle.
      Parameters:
      n - the span index
    • setKnotPosition

      public void setKnotPosition(int n, int x)
      Set a knot position.
      Parameters:
      n - the knot index
      x - the knot position
      See Also:
    • getKnotPosition

      public int getKnotPosition(int n)
      Get a knot position.
      Parameters:
      n - the knot index
      Returns:
      the knot position
      See Also:
    • knotAt

      public int knotAt(int x)
      Return the knot at a given position.
      Parameters:
      x - the position
      Returns:
      the knot number, or 1 if no knot found
    • randomize

      public void randomize()
      Randomize the gradient.
    • mutate

      public void mutate(float amount)
      Mutate the gradient.
      Parameters:
      amount - the amount in the range zero to one
    • randomGradient

      public static Gradient randomGradient()
      Build a random gradient.
      Returns:
      the new Gradient