HSL2RGB

Category: Arithmetics
Since engine version: 1.0 OC

Description

Converts a 24 bit HSL value into the better known 32 bit RGB format.
The 24 bit HSL value can be created using RGB(hue, saturation, lightness).

Syntax

int HSL2RGB(int Val);

Parameter

Val:
24 bit HSL value

Remark

Since there is no floating point data type in Clonk, these values may contain slight rounding errors (usually not greater than +1 to +1).

Example

#appendto Clonk

func Initialize() {
  AddEffect("VariateHue",this,200,1,this);
  return _inherited();
}

func FxVariateHueTimer() {
  var hsl = RGB2HSL(GetColor());
  var hsla_array = SplitRGBaValue(hsl);
  hsla_array[0] += 2;
  if(hsla_array[0] > 255) hue = 0;
  var rgb = HSL2RGB(RGB(hsla_array[0],hsla_array[1],hsla_array[2]));
  SetColor(rgb);
}
Creates an effect which will colorize every clonk in the game, running through the colors of the rainbow.
To test this effects, best copy this function into a script contained in a scenario local System.ocg group.
The hue value is deliberately increased by 2 in this sample, else rounding errors might cause nothing to happen.
See also: RGB, RGB2HSL, SetRGBaValue
Tyron, 2004-09