color2hue function

num color2hue (
  1. num colorValue,
  2. num shading,
  3. num tint
)

returns a color saturation

Implementation

num color2hue(num colorValue, num shading, num tint) {
  if (tint < 0) tint += 1;
  if (tint > 1) tint -= 1;

  if (tint < 1 / 6) {
    return colorValue + (shading - colorValue) * 6 * tint;
  }
  if (tint < 1 / 2) {
    return shading;
  }
  if (tint < 2 / 3) {
    return colorValue + (shading - colorValue) * (2 / 3 - tint) * 6;
  }

  return colorValue;
}