Class Gradient

  • All Implemented Interfaces:
    Colormap, java.lang.Cloneable

    public class Gradient
    extends ArrayColormap
    implements java.lang.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 int CIRCLE_DOWN
      Interpolate with a falling circle shape curve.
      static int CIRCLE_UP
      Interpolate with a rising circle shape curve.
      static int CONSTANT
      Don't tnterpolate - just use the starting value.
      static int HUE_CCW
      Interpolate hue counter clockwise.
      static int HUE_CW
      Interpolate hue clockwise.
      static int LINEAR
      Interpolate linearly.
      static int RGB
      Interpolate in RGB space.
      static int SPLINE
      Interpolate using a spline.
    • Constructor Summary

      Constructors 
      Constructor Description
      Gradient()
      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.
    • Constructor Detail

      • 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 Detail

      • copyTo

        public void copyTo​(Gradient g)
        Copy one Gradient into another.
        Parameters:
        g - the Gradient to copy into
      • 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(int)
      • getKnot

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

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

        public int getKnotType​(int n)
        Get a knot type.
        Parameters:
        n - the knot index
        Returns:
        the knot type
        See Also:
        setKnotType(int, int)
      • 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(int)
      • getKnotBlend

        public byte getKnotBlend​(int n)
        Get a knot blend type.
        Parameters:
        n - the knot index
        Returns:
        the knot blend type
        See Also:
        setKnotBlend(int, int)
      • 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(int)
      • removeKnot

        public void removeKnot​(int n)
        Remove a knot.
        Parameters:
        n - the knot index
        See Also:
        addKnot(int, int, int)
      • 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:
        setKnotPosition(int, int)
      • getKnotPosition

        public int getKnotPosition​(int n)
        Get a knot position.
        Parameters:
        n - the knot index
        Returns:
        the knot position
        See Also:
        setKnotPosition(int, int)
      • 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