File: gradient.pl

package info (click to toggle)
libconvert-color-perl 0.08-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 256 kB
  • sloc: perl: 1,546; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 985 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl

use strict;
use warnings;

use Convert::Color;
use Getopt::Long;

my $steps = 10;
my $space = "hsv";
my $html;

GetOptions(
   'number|n=i' => \$steps,
   'space=s' => \$space,
   'html' => \$html,
) or exit 1;

my $as_space = "as_$space";

my @start = Convert::Color->new( shift @ARGV || die "No start colour\n" )->$as_space->$space;
my @end   = Convert::Color->new( shift @ARGV || die "No end colour\n" )->$as_space->$space;

print qq[<html><body><table>\n] if $html;

foreach ( 0 .. $steps ) {
   my $alpha = $_ / $steps;

   my $col = Convert::Color->new( "$space:" . join ",", map { (1-$alpha) * $start[$_] + $alpha * $end[$_] } 0 .. 2 );

   my $rgb = $col->as_rgb8;

   if( $html ) {
      my $hex = $rgb->hex;
      printf qq[<tr><td style="background-color: #%s">#%s</td></tr>\n], $hex, $hex;
   }
   else {
      printf "%s  h: %3s, s: %3s, v: %3s\n", $rgb->hex, $col->hue, $col->saturation, $col->value;
   }
}

print qq[</table></body></html>\n] if $html;