#!/usr/bin/perl -w
######################################################################
# (c) Michael Schilli 1999
######################################################################

use Tk; 

$top = MainWindow->new();

$rot = $top->Scale(-from => 0, -to => 255, 
                   -orient => "horizontal",
                   -label => "Rot", -command => \&upd_color);
$gruen = $top->Scale(-from => 0, -to => 255, 
                     -orient => "horizontal",
                     -label => "Grün", 
                     -command => \&upd_color);
$blau = $top->Scale(-from => 0, -to => 255, 
                    -orient => "horizontal",
                    -label => "Blau", 
                    -command => \&upd_color);

$rot->pack(); 
$gruen->pack(); 
$blau->pack(); 

MainLoop;


# upd_color - Vorder- und Hintergrundfarbe aktualisieren

sub upd_color {
    my $background = "#";
    my $total      = 0;

    # Werte auslesen und numerische Farbbeschreibung aufbauen
    foreach $i ($rot,$gruen,$blau) {
        my $value = $i->get();
        $background .= sprintf("%02x", $value);
        $total += $value;
    }

    # Farbe der Beschriftung in Abhängigkeit von
    # der Gesamthelligkeit
    my $foreground = $total < 255 ? "white" : "black";

    foreach $i ($rot,$gruen,$blau) {
        $i->configure(-background => $background, 
                      -foreground => $foreground);
    }
}
