RGB2HSL

Category: Arithmetics
Since engine version: 4.9.1.0 GWE

Description

Converts a 32 bit color value into hue, saturation, and lightness values as known in painting programs.
The HSL value is returned as int and can be processed using GetRGBaValue or SplitRGBaValue.
All values range from 0 to 255.

Syntax

int RGB2HSL (int Val);

Parameter

Val:
32 bit color 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

#strict
#appendto CLNK

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

func FxVariateHueTimer() {
  var rgb, hsl=RGB2HSL(GetColorDw());
  var hue, sat, light;
  SplitRGBaValue(hsl, hue, sat, light);
  hue+=2;
  if(hue>255) hue=0;
  rgb=HSL2RGB(RGB(hue,sat,light));
  SetColorDw(rgb);
}
Creates an effect which will colorize every clonk in the game, running through the colors of the rainbow.
See also: HSL2RGB, RGB, SetRGBaValue
Tyron, September 2004