Next Tricks of the Wizards 164

Caching

        sub cmyk {
          my ($r, $g, $b) = @_;
          my ($c, $m, $y) = (1-$r, 1-$g, 1-$b);
          my $k = $c < $m ? ($c < $y ? $c : $y)
                          : ($m < $y ? $m : $y);  # Minimum
          for ($c, $m, $y) { $_ -= $k }
          [$c, $m, $y, $k];     
        }


Next Copyright © 2003 M. J. Dominus