#!/usr/bin/perl use Imager::Color; use strict; # define HSV colour option within the object initiation # my $hsv = Imager::Color->new( hsv => [ 120, 0.5, 1 ] # hue, v, s ); my @rgb = $hsv->rgba;
Update
Alternatively, if you want to roll your own conversion tool, the following code could be used, based on the converstion algorithm documentation at http://www.cs.rit.edu/~ncs/color/t_convert.html. eg.
#!/usr/bin/perl use POSIX; use strict; sub hsv2rgb { my ( $h, $s, $v ) = @_; if ( $s == 0 ) { return $v, $v, $v; } $h /= 60; my $i = floor( $h ); my $f = $h - $i; my $p = $v * ( 1 - $s ); my $q = $v * ( 1 - $s * $f ); my $t = $v * ( 1 - $s * ( 1 - $f ) ); if ( $i == 0 ) { return $v, $t, $p; } elsif ( $i == 1 ) { return $q, $v, $t; } elsif ( $i == 2 ) { return $p, $v, $t; } elsif ( $i == 3 ) { return $p, $q, $v; } elsif ( $i == 4 ) { return $t, $p, $v; } else { return $v, $p, $q; } }
In reply to Re: Converting HSV colours to RGB
by rob_au
in thread Converting HSV colours to RGB
by ropey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |