cout.x = fMin(1, (85 - H) / 42.5);

$color_r = min(1, (85 - $hue) / 42.5);


else if(H > 170)
cout.x = fMin(1, (H - 170) / 42.5);

$color_r = min(1, ($hue - 170) / 42.5);



if (H < 170)
cout.y = fMin(1, (85 - Abs(H - 85)) / 42.5);
$color_g = min(1, (85 - abs($hue - 85)) / 42.5);



if (H > 85)
cout.z = fMin(1, (85 - Abs(H - 170)) / 42.5);
$color_b = min(1, (85 - abs($hue - 170)) / 42.5);


if (S < 255)
{
cout = cout * (S / 255);

color_r * ($saturation / 255);
		$color_g = $color_g * ($saturation / 255);
		$color_b = $color_b * ($saturation / 255);
		
		
		
OffsetSaturation = /*128 **/ (255 - S) / 255;
 OffsetSaturation = 128 * (240 - S) / 240;
 
 $offset_saturation = 128 * (255 - $saturation) / 255;
 
 
 
 cout = cout * ((255 - Abs(L - 255)) / 255);
 $color_r = ((255 - abs($brightness - 255)) / 255);
 
 
 
 
 
 if (H < 0) H = (240 - H) % 240;
else H = H % 240;
if ($hue < 0) { $hue = (240 - $hue) % 240; }
else { $hue = $hue % 240; }
 
 
 
 
 
 
try another way

  L = Min(240, L);
  Color = Color * ((120 - Abs(L - 120)) / 120);

  if (L > 120) {
    OffsetLightness = 256 * (L - 120) / 120;
    Color.R += OffsetLightness;
    Color.G += OffsetLightness;
    Color.B += OffsetLightness;
    }


	$brightness = min(255, $brightness);
	color_r = color_r * ((120 - abs($brightness - 120)) / 120);
	color_g = color_g * ((120 - abs($brightness - 120)) / 120);
	color_b = color_b * ((120 - abs($brightness - 120)) / 120);
	

	if ($brightness > 120) {
		offset_brightness = 256 * ($brightness - 120) / 120;
		color_r += offset_brightness;
		color_g += offset_brightness;
		color_b += offset_brightness;
	}
	
	}
