FE 'tkGooie' Utilities

'3Dtools' group

---

Color Array Generator

(and Animated
'Circle Of Colors)

(up to 1530 colors ;
and introducing a
'miniscaleH' widget)

(FE = Freedom Environment)

FE Home Page > FE Downloads Page >

FE 'tkGooies' Description Page >

FE 'tkGooies' '3Dtools' Page >

This RGB Color Array Generator Page

INTRODUCTION to a
'Color Array Generator and Animator'

(up to 1530 shades of RYGCBM Colors)

    where
    R = Red, Y = Yellow, G = Green,
    C = Cyan, B = Blue, M = Magenta

I indicated in April 2012, on my 'biography page' at wiki.tcl.tk, that I was inspired by 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 data formats --- such as CAD-like data files, Wavefront OBJ files, Cyberware PLY files, STL stereolithography files, etc.).

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 have some nice colors for 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 this 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 format, 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.)


HELP Text

Here 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,
then repeating.

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


miniscaleH widget

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.


The code

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,
     text-array-for-labels-etc).

  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.


In addition, 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:

  • load_colorArray1530
  • animate_RYGCBM
  • writeColorTables_groupsOfSetStatements

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).


The Code

Here is a link to CODE for the script
'colorArrayGen_aniColorCircle_RYGCBM_ upto1530colors_ miniscaleH.tk'.


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 1530-set-statments generation 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.


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 because of the way our eyes react to the wavelengths of light and because of the position of the wavelengths of visible light in the frequency/wavelength spectrum --- in particular, they are within an 'octave' of each other:

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 sensitivty 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, ...


Possible Enhancements

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.

I pointed out above that 1530 has many factors --- 1530 = 5 x 2 x 3 x 3 x 17. 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 every 2 colors, every 3, every 5, every 6, every 9, every 10, every 15, every 17, every 18, every 30, every 34, every 51, every 85, every 90, every 102, every 153, every 170 of the 1,530 color array.

I may find that I use the 'every 85' set (18 colors) and 'every 90' (17 colors) and 'every 102' (15 colors) and 'every 153' (10 colors) and 'every 170' (9 colors) most often.

And I may use some variations --- like replace some magentas with browns --- for terrain colors.


CONCLUSION

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:

  • Changed the 'milsecs' var of the 'miniscaleH' proc to 'delay_milsecs' and, more importantly, fixed some increment/decrement settings in that widget-making proc.

  • Split the proc 'DrawRYGCBM' into three procs:

    • load_colorArray1530
    • animate_RYGCBM
    • writeColorTables_groupsOfSetStatements

    This makes the logic much less complicated, and thus makes the script easier to modify or enhance.

  • I have added an entry widget by which to request animating every Nth color of the 1530 colors, rather than just every color (N=1).

I replaced the old code above with the new code with these enhancements and fixes.

I plan to replace the images above with new GUI images --- showing the every-Nth-color entry field --- and 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, provide a static image of the GUI.


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 each 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
Color Array Generator (and 'Color Circle' Animation) (for up to 1530 shades of RYGCBM colors)
--- a utility in the FE 'tkGooies' system,
in the '3Dtools' group.

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.
OR ...

< Go to Top of Page, above. >

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 --- as a backup and alternative to the wiki.tcl.tk page (and site).

This page was changed 2019 Feb 23.
(Added css and javascript to try to handle text-size for smartphones, esp. in portrait orientation.)


NOTE:
The code here MAY become more 'up-to-date' than the code posted on the Tcler's Wiki --- wiki.tcl-lang.org --- formerly wiki.tcl.tk.