Class ColorUtil
Utility for handling color. Includes handle of RGB and HSL.
public static class ColorUtil
- Inheritance
-
ColorUtil
- Inherited Members
Properties
EnvDiscreteRgbSeed
public static int EnvDiscreteRgbSeed { get; set; }
Property Value
- int
The seed is applied to GetDiscreteRGB_Env(double, double).
ExceptionRed
Exception RGB. Also for nan value.
public static Vec3d ExceptionRed { get; }
Property Value
Gray
Generate gray color. RGB=(0.2, 0.2, 0.2).
public static Vec3d Gray { get; }
Property Value
NoValueGreen
No value RGB.
public static Vec3d NoValueGreen { get; }
Property Value
NullDark
Generate dark RGB for null value. RGB=(0,0,0).
public static Vec3d NullDark { get; }
Property Value
UndeterminedPurple
Undetermined RGB.
public static Vec3d UndeterminedPurple { get; }
Property Value
Methods
GetDiscreteRGBWithoutPurpleAndRed(int, double, double)
Get discrete RGB without purple and red color ranges.
public static Vec3d GetDiscreteRGBWithoutPurpleAndRed(int seed, double saturation = 1, double light = 0.5)
Parameters
seed
intColor seed. Determines the hue value.
saturation
doubleSaturation value of the color.
light
doubleLight value of the color.
Returns
- Vec3d
RGB color vector without purple and red ranges.
GetDiscreteRGB_Env(double, double)
Get discrete color using EnvDiscreteRgbSeed. The functionality is the same as GetDiscreteRgb(int, double, double). The function call makes EnvDiscreteRgbSeed plus 1.
public static Vec3d GetDiscreteRGB_Env(double saturation = 1, double light = 0.5)
Parameters
Returns
- Vec3d
RGB
GetDiscreteRgb(int, double, double)
Get discrete color(RGB). The term ‘discrete’ means there is big color difference between nearby seed. This function is good to auto set color for lot of components.
public static Vec3d GetDiscreteRgb(int seed, double saturation = 1, double light = 0.5)
Parameters
seed
intcolor seed. Determine the hue value by BinaryDividentSequence(int).
saturation
doublesaturation
light
doublelight
Returns
- Vec3d
RGB
GetDiscreteRgbByBoundary(int, double, double, double, double)
Get discrete RGB by boundary.
public static Vec3d GetDiscreteRgbByBoundary(int seed, double hueBegin = 0, double hueEnd = 1, double saturation = 1, double light = 0.5)
Parameters
seed
intColor seed. Determines the hue value.
hueBegin
doubleThe beginning of the hue range.
hueEnd
doubleThe end of the hue range.
saturation
doubleSaturation value of the color.
light
doubleLight value of the color.
Returns
- Vec3d
RGB color vector with boundary.
GetGloomyColor(object, double, double)
The default value is blue tune.
public static Vec3d GetGloomyColor(this object seed, double hueMin = 0.5, double hueMax = 0.7)
Parameters
Returns
GetRgb(double, RatioRgbFuncEnum)
Get RGB by funcEnum
.
public static Vec3d GetRgb(double v, RatioRgbFuncEnum funcEnum)
Parameters
v
doublevalue
funcEnum
RatioRgbFuncEnumfunction enum
Returns
- Vec3d
RGB
GetRgbByErf(double)
Get RGB interpolated from blue to green to red by erf function. The range suits for -2 to 0 to 2.
public static Vec3d GetRgbByErf(double v)
Parameters
v
doubleinput of the erf
Returns
- Vec3d
RGB
GetRgbByHslOffset(Vec3d, Vec3d)
Convert RGB by HSL offset.
This is a three step process: RGB convert to HSL, HSL+=hslOffset
, HSL convert to RGB.
public static Vec3d GetRgbByHslOffset(Vec3d rgb, Vec3d hslOffset)
Parameters
Returns
- Vec3d
RGB
GetRgbByLinearRatio(double)
0 ~ 0.5 ~ 1 is linearly interpolated to blue to green to red. The below range data is pure blue. The exceeding range data is pure red.
public static Vec3d GetRgbByLinearRatio(double ratio)
Parameters
ratio
doublethe interpolation range is 0~1
Returns
- Vec3d
RGB
GetRgbByNormalizedErf(double)
0 ~ 0.5 ~ 1 is interpolated to blue to green to red.
The below range data is pure blue. The exceeding range data is pure red.
return GetRgbByLinearRatio(MathUtil.Erf(ratio*2) / MathUtil.Erf(2));
public static Vec3d GetRgbByNormalizedErf(double ratio)
Parameters
ratio
doublethe interpolation range is 0~1
Returns
- Vec3d
RGB
GetRgbByNormalizedPositiveErf(double)
0 ~ 0.5 ~ 1 is interpolated to blue to green to red.
The below range data is pure blue. The exceeding range data is pure red.
Only the positive half form is used.
return GetRgbByLinearRatio(MathUtil.Erf(ratio*2) / MathUtil.Erf(2));
public static Vec3d GetRgbByNormalizedPositiveErf(double ratio)
Parameters
ratio
doublethe interpolation range is 0~1
Returns
- Vec3d
RGB
GetRgbByPositiveErf(double)
Get RGB interpolated from blue to green to red by modified erf function.
public static Vec3d GetRgbByPositiveErf(double v)
Parameters
v
doubleinput of the modified erf
Returns
- Vec3d
color
Remarks
If v
is equal or lower than 0, the color is blue;
if v
is equal or larger than 1, the color is red;
otherwise, the color varied from blue to green to red by modified erf function.
GetRgbByPositiveErf(double, double, double)
Get RGB interpolated from blue to green to red by modified erf function.
public static Vec3d GetRgbByPositiveErf(double v, double floor, double ceil)
Parameters
Returns
- Vec3d
color
Remarks
If v
is equal or lower than floor
, the color is blue;
if v
is equal or larger than ceil
, the color is red;
otherwise, the color varied from blue to green to red by modified erf function.
HslToRgb(Vec3d)
Convert color convention from HSL to RGB.
public static Vec3d HslToRgb(Vec3d hsl)
Parameters
hsl
Vec3dHSL
Returns
- Vec3d
RGB
HslToRgb(double, double, double)
Convert color convention from HSL to RGB.
public static Vec3d HslToRgb(double hue, double saturation, double light)
Parameters
Returns
- Vec3d
RGB
RgbToHsl(Vec3d)
Convert color convention from RGB to HSL.
public static Vec3d RgbToHsl(Vec3d rgb)
Parameters
rgb
Vec3dRGB
Returns
- Vec3d
HSL
RgbToHsl(double, double, double)
Convert color convention from RGB to HSL.
public static Vec3d RgbToHsl(double r, double g, double b)
Parameters
Returns
- Vec3d
HSL
ToDualHexString(Vec3d)
Converts an RGB color vector to a hexadecimal string representation.
public static string ToDualHexString(Vec3d rgb)
Parameters
rgb
Vec3dThe RGB color vector to convert.
Returns
- string
A hexadecimal string representation of the RGB color.