if ($h < $tol OR $h > 1-$tol) { if ($h < $tol) { $dist = ($tol-$h); } else if ($h > 1-$tol) { $dist = ($h - (1-$tol)); } $s = $s * ($dist/$tol); if ($s > 1) $s = 1; $h = 0; }