#!/usr/bin/perl -w

require "../b/tk/pl/color_model";
use strict;
my (@input, $fh);

# range of hue: 0-5.99
# color code: R Y G C B M
@input = <<eof;
    :link { color: #"2.8,0.6"; }
    :visited { color: #"3.5,0.6"; }
    em, .em { color: #"0,1"; }
    .search_keyword { background: #"3,0.1"; font-weight:bold; }
    code, .code { color: #"2,0.8"; }
    dfn { color: #"5,0.8"; }

    blockquote.celebrity { background: #"1,0.3"; }
    .quote, blockquote { color: #"0,0.7"; }
    pre.mail { color: #"0,0.7"; }
    .hilight1 { background: #"1,0.3"; }
    .hilight2 { background: #"3,0.3"; }
    .hilight3 { background: #"5,0.3"; }
    .alert { background: #"0,0.8"; }

    pre.docsrc { background:#"3,0.3"; }
    .kbd { color: #"2,0.8"; background: #"5,0.3"; }
    .tag, .post-tags li { background: #"3,0.2"; }

    .magic { background: #"0,0"; }
    .gray_out { color: gray; }

    .toc { background: #"0.8,0.3"; }
    div#toc { background: #"0.8,0.3"; }
    div#nav, .nav, div#footer { background: #"4.3,0.3"; }
    div#nav a:hover { background: #"0,0"; }
    div#nav a:hover .hovertext { color: #"2,0.8"; }
    div#nav a:hover .hovertext em { background: #"4.9,0.8"; }

    /* http://flowplayer.org/tools/tooltip/index.html */
    .jq_tooltip { background: #"1,0.4"; padding: 2px; width: 10em }
}
eof

sub convert {
    my ($hs, $b) = @_;
    my ($h, $s) = split /,/, $hs;
    my (@rgb) = HSBtoRGB($h/6.0, $s, $b);
    sprintf "%02x%02x%02x", int($rgb[0]*255.9),
	int($rgb[1]*255.9), int($rgb[2]*255.9);
}

sub do_it {
    my ($fh, $fg, $bg) = @_;
    my ($line, $t);
    foreach $line (@input) {
	$t = $line;
	$t =~ s/color:\s*#"(.*?)";/"color: #" . convert($1,$fg) . ";"/eg;
	$t =~ s/background:\s*#"(.*?)";/"background: #" . convert($1,$bg) . ";"/eg;
	print $fh $t;
    }
}

open $fh, "> light.css";
print $fh <<'eof';
/* light.css */
@media screen {
    body, slide { color: #000; background: #ffd; }
    .strong { background: #ffa; }
eof
do_it($fh, 0.3, 1.0);
close $fh;

open $fh, "> dark.css";
print $fh <<'eof';
/* dark.css */
@media screen {
    body { color: #0f8; background: #000; }
    .strong { background: #220; }
eof
do_it($fh, 1.0, 0.4);
close $fh;

