FE 'tkGooie' Utilities
A generator of Tcl code
--- 'set' statements --- to
load an array of colors
the RGB and CMY
gamut of colors
with display of the
FE Home Page >
FE Downloads Page >
FE 'tkGooies' Description Page >
FE 'tkGooies' '3Dtools' Page >
This RGB Color Array Generator Page
INTRODUCTION to a
I indicated in April 2012, on my 'biography page' at the Tclers' Wiki at wiki.tcl.tk, that I was inspired by the 3D model viewers of Mark Stucky and Gerhard Sookahet to create some 3D model viewing utilities --- complete with fairly robust 3D model data importers --- for a variety of 3D ( ASCII, not binary ) data formats --- such as
Well, I am getting started on some 3D viewing projects, and I am starting to put together some test 3D models.
I would like to, eventually, apply some nice colors to the facets (polygons) and/or vertices of these models.
So I have been giving some thought to the nice colors that can be made from the RGB ('primary', 'additive') colors and the CMY ('complementary', 'subtractive') colors.
If you have seen an image of the 'HSV hexcone', like the following, you probably know what I am talking about.
In fact, I am talking about 'going through' the colors on the perimeter of the circle at the top of that cone --- as seen in the following image.
I decided to put together a GUI utility that shows me those colors --- AND gradations between them --- along with the capability to generate a set of Tcl 'set' statements that can be used to set up a 'color array' variable that can be used as a 'look up table' to assign colors to facets and vertices.
Here is an animated GIF image of the GUI that gives an idea of what I am talking about.
The actual GUI goes through the colors much more smoothly.
(In fact, I may replace this animated GIF by a movie file someday.
With the good compression ratios of movies nowadays, using H.264 video compression, for example, it is possible to get movie files that are actually more compact than their corresponding, but not so smooth, GIF animations --- in cases where the successive images are not changing in very many pixel locations.
Unfortunately, that may not be the case with this animation, in which the color of almost EVERY pixel in each 'frame' is changed.)
Below is the text from the 'Help' button in the GUI --- to give you more clarity on what this Tk script does:
** HELP for this RYGCMB Color Circle Animation and
Tcl-Color-Array-Setting-Statements Generator Utility **
This Tk GUI script 'travels around' the 'color circle' ---
through the 6 primary and complementary colors ---
Red-Yellow-Green-Cyan-Blue-Magenta --- and back to Red,
The phrase 'travel around', in this particular GUI, means
that a sequence of colors, gradiating between pairs of the
6 RYGCBM colors, is displayed in a 'color swatch' on the GUI.
The animation continues until the user clicks the Stop button ---
or the user can click the Exit button --- or close the window.
Thus this script provides a repeating color-sequence animation.
The color sequence is somewhat similar to the color spectrum
of a prism or rainbow.
This animation gives the user a quick, dynamic overview of the
color combinations of the primary and complementary colors as one
blends the colors in the rather natural sequence RYGCBMR.
A SECOND (probably more useful) PURPOSE of this GUI is to generate
a file containing 'set' statements for an ARRAY OF 1530 COLORS.
In addition to the animation, this GUI provides an array of the
the 6 x 255 = 1530 hexcolors traversed. The 'set' statements for
the array are put in a text file.
The 'set' statements can be used in other Tk scripts to set up
a 'look-up table' of colors. For example, in a 3D modeling
application, one may wish to apply colors to the facets (polygons)
or vertices of a 3D model --- either randomly or via some pattern.
Integers in the range 1 to 1530 (or some subset thereof) can be
generated --- randomly or in some algorithmic pattern --- to
apply look-up colors to facets of the model.
(Note that since 1530 has many factors --- 1530 = 5 x 2 x 3 x 3 x 17
--- there are quite a few subsets of 'equally-spaced' colors
that you can use to cycle 'nicely' through those 1530 colors.
Every 2 colors, every 3, every 5, every 6, every 9, every 10,
every 15, every 17, every 18, ...)
A THIRD PURPOSE of this GUI - demo of a NEW WIDGET:
This script also introduces a new scale-like widget,
dubbed 'miniscaleH' (for miniscale-horizontal) ---
to control the speed of the color transition (color
steps per second --- from about 50 to 1000 per second).
(At 1 per second, it would take 25 minutes to traverse
the 1530 steps and start over. A setting in the range
of 50 to 400 is probably more suited to those with other
things to do.)
The 'miniscaleH' widget is made up of 4 'button' widgets
and one 'label' widget --- arrayed from left to right ---
the label in the middle, with 2 buttons on either side.
The '+' and '++' buttons on the right increment the scale numbers;
the '-' and '--' buttons on the left decrement. The '++' and
'--' buttons are for high-speed incrementing/decrementing.
The 'miniscaleH' widget is more compact than the 'scale'
widget --- and its labels and buttons can be decorated
with background images, via the '-image' and
'-compound center' options. So the 'miniscaleH' widget
may have some use in 'embellished' Tk GUI's. In contrast,
the 'scale' widget does not have a '-image' option.
* END OF THE HELP text
On the subject of the 'miniscaleH' widget, I would just like to point out that it is a 'horizontal' variation on the 'miniscale' widget that I devised for the GUI that I presented at A color-gradient-button-maker GUI with 6 'miniscale' widgets.
AND ... because I can decorate the 'miniscaleH' widget with background images on the 4 buttons and the label from which the 'miniscaleH' widget is made, I may return to the Tk-GUI-embellishment project that I published at Version 2 of a demo of THEMES for Tk GUI's, using images and colors and replace the 'scale' widget in that demo GUI with the 'miniscaleH' widget --- but enhanced with background images.
I provide the code for this 1530-color RYGCBMR animation (and color-array 'set'-statements generator) GUI below.
I follow my usual 'canonical' structure for Tk code, for this Tk script:
0) Set general window & widget parms (win-name, win-position,
win-color-scheme, fonts, widget-geometry-parms, win-size-control,
1a) Define ALL frames (and sub-frames, if any).
1b) Pack ALL frames and sub-frames.
2) Define & pack all widgets in the frames, frame by frame.
3) Define keyboard and mouse/touchpad/touch-sensitive-screen action
BINDINGS, if needed.
4) Define PROCS, if needed.
5) Additional GUI initialization (typically with one or more of
the procs), if needed.
This makes it easy for me to find code sections --- while generating and testing this script, and when looking for code snippets to include in other scripts (code re-use).
Since this script also includes a proc to generate the 'miniscaleH' widget, I have added the following step to the typical code structure outline above:
1c) Provide proc(s) to be used to define widget(s) made from other Tk widgets.
In addition, I call your attention to step-zero.
One new thing that I have started doing recently (circa 2012) is to use a text-array for text in labels, buttons, and other widgets in the GUI.
This can make it easier for people to internationalize my scripts.
I will be using a text-array like this in most of my scripts in the future.
Experimenting with the GUI
As in all my scripts that use the 'pack' geometry manager (which is all of my 100-plus scripts, so far), I provide the four main 'pack' parameters --- '-side', '-anchor', '-fill', '-expand' --- on all of the 'pack' commands for the frames and widgets.
That helps me when I am initially testing the behavior of a GUI (the various widgets within it) as I resize the main window.
You can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various frames and widgets --- to get the widget behavior that you want.
You might want to change the fonts used for the various GUI widgets.
For example, you could change '-weight' from 'bold' to 'normal' --- or '-slant' from 'roman' to 'italic'. Or change font families.
In fact, you may NEED to change the font families, because the families I used may not be available on your computer --- and the default font that the 'wish' interpreter chooses may not be very pleasing.
I use variables to set geometry parameters of widgets --- parameters such as border-widths and padding. And I have included the '-relief' parameter on the definitions of frames and widgets.
Feel free to experiment with those 'appearance' parameters as well.
Some features of the code
That said, here's the code --- with plenty of comments to describe what most of the code-sections are doing.
The code that generates the 1530 colors for the animation, and the code that does the animation, and the code for writing the color-arrays file is in three procs:
It is my hope that the copious comments in the code will help Tcl-Tk coding 'newbies' get started in making GUI's like this --- and perhaps learn to make new widgets (such as even more variations on the 'miniscale' widget).
Without the comments, it might not be clear how the 'stopani0or1' flag, for example, is being used to stop the animation as needed.
Without the comments, potential young Tcler's might be tempted to return to their iPhones and iPads and iPods --- to watch LFHV (Luxembourg's Funniest Home Videos).
Here is a link to CODE for the script
Setting the Text Editor to use
Note that the user can set the variable 'EDITOR_text' at the bottom of the script to choose an appropriate GUI text editor in which the file of Tcl 'set' statements will be shown.
The editor is called up from within the Tk script by using the Tcl 'exec' command.
The genration of the 1530 'set' statments is so fast that IMMEDIATELY after clicking on the 'WriteTables' button, the text-editor pops up displaying the 'set'-statements file.
You can change the name of an array variable if you wish, and save the file in a directory of your choice --- with the text editor.
Sensitivity to Color Components
I find it interesting to note that a lot of the reason we center our attention on the RGB colors (and the CMY pigments that 'suck' those colors out of reflected light) is
Note that the peaks are within an 'octave' of each other. This is probably a good thing. Otherwise, harmonics (multiples of these frequencies) might excite the light sensors in our eyes --- as well as the frequencies in this 'visible range'. That might not be good for survival of a species.
It is reported that some animals do not see all the colors that we see. Unlucky them.
In my case, I am partially red-green blind.
I think if my sensitivity to red and green were plotted like this, my red and green 'humps' might be about as tall as that 'blue' hump.
Maybe that is why blue is my favorite color. In any case, ...
I plan to enhance this script so that it puts out smaller groups of 'set' statements --- corresponding to subsets of the 1,530 set statements --- all in the same output file.
Then, when I need an array of about 20 'set' statements, say, to make an array of about 20 'equally spaced' colors for another Tk script, I can run this utility and extract out the group of 'set' statements that I need.
The number 1530 has many factors --- 1530 = 6 x 255 = 2 x 3 x 3 x 5 x 17 --- as noted above in the HELP section.
So there are quite a few subsets of 'equally-spaced' colors that you can use to cycle 'nicely' through those 1530 colors.
I will probably make subsets of 'set' statements from even-divisors of 1530 :
of the 1,530 color array.
I may find that I use the
And I may use some variations --- like replace some magentas with browns --- for terrain colors.
It took a couple of days to get this code in shape.
But now I am in a position to generate some 3D model files and liven them up some with a variety of colors.
Tcl-Tk, you make me :-) .
2013jan26 UPDATE :
I have implemented the 'Possible Enhancements' listed above --- namely, I have added many sub-groups of the original 1,530 colors to the 'set' statements in the output 'ColorTables' text file.
In addition, I have made a few other changes:
I replaced the old code above with the new code with these enhancements and fixes.
Someday I may replace the images above with new GUI images --- showing the every-Nth-color entry field.
And I may replace the crude animated GIF above with a small movie file that shows the color transition much more smoothly.
And as a backup, for those who cannot see the movie file, I may provide a static image of the GUI.
Alternative display of the colors
I have found that the color animation is not the best way of getting a good idea of the 'spread' of colors in any of the approximately 20 color tables generated by this script.
It may be better to devise a script that shows any of the color tables as a stack of colored rectangles.
Someday I may provide such a script as an alternative to this way of generating and viewing some color tables.
Bottom of this page for a
To return to a previously visited web page location, click on the
Back button of your web browser a sufficient number of times.
OR, use the History-list option of your web browser.
The first releasable version of the code was posted in 2012 Nov at http://wiki.tcl.tk/37296.
This FE web page was created 2015 Mar 18.