Created
March 6, 2017 08:33
-
-
Save hfs/ba1182b5e658999d63088095a56b6239 to your computer and use it in GitHub Desktop.
Generate a rainbow color table with 256 entries as CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; | |
} | |
} | |
for (0..255) { | |
my ($r, $g, $b) = map { floor($_ * 255) } hsv2rgb((255 - $_), 1, 1); | |
print ".v$_ { background-color: "; | |
printf("#%02x%02x%02x", $r, $g, $b); | |
print "; }\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment