Package org.evoludo.simulator
Class ColorMap.Gradient1D<T>
Object
ColorMap<T>
ColorMap.Gradient<T>
Gradient1D<T>
- Type Parameters:
T- type of color object: String orMeshLambertMaterialfor GWT andColorfor JRE
- Direct Known Subclasses:
ColorMap.Hue,ColorMap3D.Gradient1D,ColorMapCSS.Gradient1D
One dimensional color gradient spanning two or more colors
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class ColorMap
ColorMap.Gradient<T>, ColorMap.Gradient1D<T>, ColorMap.Gradient2D<T>, ColorMap.GradientND<T>, ColorMap.Hue<T>, ColorMap.Index<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected T[]Reference to pre-allocated gradient colors.protected doubleHelper variable to make the mapping from a range of data values to indices of the gradient array more efficient:map=nBins/(max-min), wheremaxmaximum data value to be mapped.protected doubleMinimum data value.protected final intNumber of colors in the gradient:nGradient+1.protected final intThe index of the trait that this gradient refers to (or-1if not applicable). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGradient1D(Color[] colors, int trait, T[] gradient) For internal use only.protectedGradient1D(T[] gradient) For internal use only.protectedGradient1D(T[] gradient, int trait) For internal use only. -
Method Summary
Modifier and TypeMethodDescriptionprotected intbinOf(double value) Utility method to calculate the index of the gradient color that corresponds tovalue.voidAssign a newcolorto the gradient forvalue.voidAssign a newcolorto the gradient forvaluewith transparencyalpha.voidsetGradient(Color[] colors) Sets the gradient to span the colors in the arraycolors.voidsetGradient(Color[] colors, int trait) Sets the gradient for the trait with indextraitto span the colors in the arraycolors.voidsetRange(double min, double max) Sets the range of values spanned by the gradient to[min,max].translate(double data) Translate thedoublevaluedatato a color gradient.booleanTranslate thedata1anddata2arrays ofdouble[]multi-trait values to colors and store the results in thecolorarray.booleanTranslate thedataarray ofdouble[]multi-trait values to colors and store the results in thecolorarray.booleanTranslate thedataarray ofdoublevalues to colors and store the results in thecolorarray.Methods inherited from class ColorMap.Gradient
interpolateColors, interpolateColorsMethods inherited from class ColorMap
addAlpha, addAlpha, addColors, blendColors, blendColors, color2Color, translate, translate
-
Field Details
-
gradient
Reference to pre-allocated gradient colors. -
nGradient
protected final int nGradientNumber of colors in the gradient:nGradient+1. -
min
protected double minMinimum data value. This value is mapped onto colorgradient[0]. -
map
protected double mapHelper variable to make the mapping from a range of data values to indices of the gradient array more efficient:map=nBins/(max-min), wheremaxmaximum data value to be mapped. -
trait
protected final int traitThe index of the trait that this gradient refers to (or-1if not applicable).
-
-
Constructor Details
-
Gradient1D
For internal use only. Construct color gradient running through all the colors in the arraycolorsfor the trait with indextrait(or-1if not applicable). The gradient colors of typeTare stored ingradient. The number of interpolated intermediate colors between two subsequent entries incolorsis(gradient.length-1)/(N-1), whereNis the number of colors incolors. The default range for mapping data values onto the color gradient is[0.0, 1.0].- Parameters:
colors- the equally spaced reference colors of the gradienttrait- the trait index for the color gradientgradient- the array to store the gradient colors- See Also:
-
Gradient1D
For internal use only. Initializes gradient based on the supplied arraygradientof typeT.- Parameters:
gradient- the array to store the gradient colors
-
Gradient1D
For internal use only. Initializes gradient based on the supplied arraygradientof typeTfor trait with indextrait. The default range for mapping data values onto the color gradient is[0.0, 1.0].- Parameters:
gradient- the array to store the gradient colorstrait- the trait index for the color gradient- See Also:
-
-
Method Details
-
setColor
Assign a newcolorto the gradient forvalue.- Parameters:
value- the value of thecolorcolor- the new color forvalue
-
setColor
Assign a newcolorto the gradient forvaluewith transparencyalpha.Note: the transparency of the supplied color is always honoured but overruled if
alpha != 255.- Parameters:
value- the value of thecolorcolor- the new color forvaluealpha- the transparency of the new color
-
binOf
protected int binOf(double value) Utility method to calculate the index of the gradient color that corresponds tovalue. Returns-1ifvalueis invalid or lies outside the range of the gradient.- Parameters:
value- the value to convert to a bin index of the gradient- Returns:
- the index of the bin or
-1
-
setGradient
Sets the gradient to span the colors in the arraycolors.- Parameters:
colors- the array of colors for the gradient
-
setGradient
Sets the gradient for the trait with indextraitto span the colors in the arraycolors.- Parameters:
colors- the array of colors for the gradienttrait- the trait index for the color gradient
-
setRange
public void setRange(double min, double max) Sets the range of values spanned by the gradient to[min,max].- Parameters:
min- the minimum value of the gradientmax- the maximum value of the gradient
-
translate
Description copied from class:ColorMap.GradientTranslate thedoublevaluedatato a color gradient. The type of object returned depends on the implementation.- Overrides:
translatein classColorMap.Gradient<T>- Parameters:
data- thedoublevalue to convert to a color- Returns:
- the color object
-
translate
Translate thedataarray ofdoublevalues to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.Note: whether
datarefers to a single or multiple traits is up to the implementation to decide. For example,CXPopulationstores multiple traits in a linear array.Implementation: For performance reasons no validity checks on
data. In particular, all data entries must lie inside the range for mapping data values. -
translate
Translate thedataarray ofdouble[]multi-trait values to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.Implementation:
- Each entry in
datais assumed to be one dimensional (only first entry used) and converted to the corresponding gradient color and returned in thecolorarray. - For performance reasons no validity checks on
data. In particular, all data entries must lie inside the range for mapping data values.
- Each entry in
-
translate
Translate thedata1anddata2arrays ofdouble[]multi-trait values to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.For example, frequencies and fitnesses, say
data1anddata2, respectively, yield the average fitness asdata1·data2(dot product), which then gets converted to a color.
-