in reply to Converting HSV colours to RGB
#!/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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Converting HSV colours to RGB
by ropey (Hermit) on Jan 17, 2002 at 16:56 UTC | |
by Anonymous Monk on May 15, 2013 at 16:53 UTC | |
by djconnel (Initiate) on Feb 15, 2016 at 20:13 UTC |