# the next line restarts using wish \
exec wish "$0" "$@"
# tcolor --
# This script implements a simple color editor, where you can
# create colors using either the RGB, HSB, or CYM color spaces
# and apply the color to existing applications.
#
# SCCS: @(#) tcolor 1.10 96/02/16 10:49:25
# Global variables that control the program:
#
# colorSpace - Color space currently being used for
# editing. Must be "rgb", "cmy", or "hsb".
# label1, label2, label3 - Labels for the scales.
# red, green, blue - Current color intensities in decimal
# on a scale of 0-65535.
# color - A string giving the current color value
# in the proper form for x:
# #RRRRGGGGBBBB
# updating - Non-zero means that we're in the middle of
# updating the scales to load a new color,so
# information shouldn't be propagating back
# from the scales to other elements of the
# program: this would make an infinite loop.
# command - Holds the command that has been typed
# into the "Command" entry.
# autoUpdate - 1 means execute the update command
# automatically whenever the color changes.
# name - Name for new color, typed into entry.
set colorSpace hsb
set red 65535
set green 0
set blue 0
set color #ffff00000000
set updating 0
set autoUpdate 1
set name ""
# Create the menu bar at the top of the window.
-command "destroy ."
# Create the command entry window at the bottom of the window, along
# with the update button.
# Create the listbox that holds all of the color names in rgb.txt,
# if an rgb.txt file can be found.
continue;
}
set f [open $i]
-relief sunken -borderwidth 2 -exportselection false
}
-relief sunken -borderwidth 2
}
}
close $f
break
}
# Create the three scales for editing the color, and the entry for
# typing in a color value.
foreach i {1 2 3} {
label .label$i -textvariable label$i
-command tc_scaleChanged
}
# Create the color display swatch on the right side of the window.
# The procedure below is invoked when one of the scales is adjusted.
# It propagates color information from the current scale readings
# to everywhere else that it is used.
if $updating {
return
}
} else {
} else {
}
}
}
# The procedure below is invoked to update the scales from the
# current red, green, and blue intensities. It's invoked after
# a change in the color space and after a named color value has
# been loaded.
set updating 1
} else {
} else {
}
}
set updating 0
}
# The procedure below is invoked when a named color has been
# selected from the listbox or typed into the entry. It loads
# the color into the editor.
} else {
}
}
}
}
# The procedure below is invoked when a new color space is selected.
# It changes the labels on the scales and re-loads the scales with
# the appropriate values for the current color in the new color space
return
}
return
}
set label2 Saturation
set label3 Brightness
return
}
}
# The procedure below converts an RGB value to HSB. It takes red, green,
# and blue components (0-65535) as arguments, and returns a list containing
# HSB components (floating-point, 0-1) as result. The code here is a copy
# of the code on page 615 of "Fundamentals of Interactive Computer Graphics"
# by Foley and Van Dam.
} else {
}
} else {
}
}
if {$max == 0} {
set sat 0
} else {
}
if {$sat == 0} {
set hue 0
} else {
} else {
} else {
}
}
if {$hue < 0.0} {
}
}
}
# The procedure below converts an HSB value to RGB. It takes hue, saturation,
# and value components (floating-point, 0-1.0) as arguments, and returns a
# list containing RGB components (integers, 0-65535) as result. The code
# here is a copy of the code on page 616 of "Fundamentals of Interactive
# Computer Graphics" by Foley and Van Dam.
if {$sat == 0} {
return "$v $v $v"
} else {
if {$hue >= 6.0} {
set hue 0.0
}
case $i \
0 {return "$v $t $p"} \
1 {return "$q $v $p"} \
2 {return "$p $v $t"} \
3 {return "$p $q $v"} \
4 {return "$t $p $v"} \
5 {return "$v $p $q"}
error "i value $i is out of range"
}
}
# The procedure below is invoked when the "Update" button is pressed,
# and whenever the color changes if update mode is enabled. It
# propagates color information as determined by the command in the
# Command entry.
eval $newCmd
}