File: 031_color_hsv

package info (click to toggle)
libpdf-builder-perl 3.027-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,992 kB
  • sloc: perl: 107,532; makefile: 10
file content (57 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download | duplicates (4)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

# display a subset of possible HSV colors. 
# TBD: consider at least more Values pages (currently 8 and 10-15).

use strict;
use warnings;

use PDF::Builder;
use PDF::Builder::Util;
use POSIX;
use Math::Trig;

#my $compress = 'none'; # uncompressed streams
my $compress = 'flate'; # compressed streams

my $cx = 300;
my $cy = 400;
my $cr = 15;
my $cs = 32;
my $ang = 30;

my $pdf = PDF::Builder->new(-compress => $compress);
$pdf->mediabox(595,842);

my $fnt = $pdf->corefont('Verdana-Bold');

# the 7 pages output are 7 levels of Value (why not anything less than 8?)
foreach my $v (0xf, 0xE, 0xd, 0xC, 0xb, 0xA, 0x8) {
    my $page = $pdf->page();
    my $gfx = $page->gfx();
    my $text = $page->text();
    
    $text->textlabel(300,750, $fnt,20, 'HSV Colorspace', -color=>'#000', -hscale=>125, -center=>1);

    $text->strokecolor('#000');
    foreach my $s (0 .. 0x7) {
        my $ha = $s/2;
        foreach my $h (0 .. (12*$ha)-1) {
		
            my $t = sprintf('&%02X%02X%02X', floor(256*$h/(12*$ha)), (($s*2)<<4|($s*2)), ($v<<4|$v));
            $gfx->fillcolor($t);
            $gfx->circle($cx+cos(deg2rad(360*$h/(12*$ha)))*$cs*$s,$cy+sin(deg2rad(360*$h/(12*$ha)))*$cs*$s, $cr);
            $gfx->fillstroke();
            $text->textlabel($cx+cos(deg2rad(360*$h/(12*$ha)))*$cs*$s,$cy-2+sin(deg2rad(360*$h/(12*$ha)))*$cs*$s, $fnt,6, $t, -color=>'#000', -hscale=>80, -center=>1);
        }
    }
}

$pdf->saveas("$0.pdf");
$pdf->end();

exit;

__END__