You can perform such conversions using the Imager::Color module. eg.

#!/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; } }
perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

In reply to Re: Converting HSV colours to RGB by rob_au
in thread Converting HSV colours to RGB by ropey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.