Table of Contents

Class ColorUtil

Namespace
Hi.Coloring
Assembly
HiGeom.dll

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

Vec3d

Gray

Generate gray color. RGB=(0.2, 0.2, 0.2).

public static Vec3d Gray { get; }

Property Value

Vec3d

NoValueGreen

No value RGB.

public static Vec3d NoValueGreen { get; }

Property Value

Vec3d

NullDark

Generate dark RGB for null value. RGB=(0,0,0).

public static Vec3d NullDark { get; }

Property Value

Vec3d

UndeterminedPurple

Undetermined RGB.

public static Vec3d UndeterminedPurple { get; }

Property Value

Vec3d

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 int

Color seed. Determines the hue value.

saturation double

Saturation value of the color.

light double

Light 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

saturation double

saturation

light double

light

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 int

color seed. Determine the hue value by BinaryDividentSequence(int).

saturation double

saturation

light double

light

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 int

Color seed. Determines the hue value.

hueBegin double

The beginning of the hue range.

hueEnd double

The end of the hue range.

saturation double

Saturation value of the color.

light double

Light 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

seed object
hueMin double
hueMax double

Returns

Vec3d

GetRgb(double, RatioRgbFuncEnum)

Get RGB by funcEnum.

public static Vec3d GetRgb(double v, RatioRgbFuncEnum funcEnum)

Parameters

v double

value

funcEnum RatioRgbFuncEnum

function 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 double

input 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

rgb Vec3d

RGB

hslOffset Vec3d

HSL offset

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 double

the 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 double

the 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 double

the 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 double

input 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

v double

input of the modified erf

floor double

floor value of v

ceil double

ceil value of v

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 Vec3d

HSL

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

hue double

hue

saturation double

saturation

light double

light

Returns

Vec3d

RGB

RgbToHsl(Vec3d)

Convert color convention from RGB to HSL.

public static Vec3d RgbToHsl(Vec3d rgb)

Parameters

rgb Vec3d

RGB

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

r double

red

g double

green

b double

blue

Returns

Vec3d

HSL

ToDualHexString(Vec3d)

Converts an RGB color vector to a hexadecimal string representation.

public static string ToDualHexString(Vec3d rgb)

Parameters

rgb Vec3d

The RGB color vector to convert.

Returns

string

A hexadecimal string representation of the RGB color.