It is with great pride that I share my new Custom Color Wheel function. What started out as a one-day project grabbed hold of me, and it took me 12 days to complete.
This function may come in handy for anyone who is working on a paint program, or any customization routine, or any program in which the programer would like to give the user more than a dozen colors to choose from. The demonstration program calls on the ColorWheel function so that you can choose a color for the screen. (Yeah, I know. It's a boring example. But I think you will recognize the potential.)
Rendering all of those colors was a real challenge as the SETPIXEL command is deathly slow. To manage this limitation, the Function attempts to load a PNG image of the colorwheels, and only if that file can not be found does it render a new set of color wheels and saves them to the PNG image file for next time. The down side to loading the PNG image is that the calculations for pixel color selection are highly dependent on the loaded image being in EXACTLY the right place, so if the screensize is changed, the image file will no longer map to the calculated values. Therefore, if you change the screen size, you will need to either delete the colorwheel PNG image from the CWFILES folder, or you will need to set Delete_ColorWhl_Flg = TRUE for a single run of the program. I apologize for the hassle, but it is worth it for the speed gained in loading the image rather than generating it from scratch.
The PNG image file is not included, so the first time you run this function, it will render the color wheels to match your system as you watch; and then it will save the PNG image to the CWFILES folder. I tried rendering the wheels off-screen, which was faster, but also much more boring. Rendering on screen gives you something to look at.
You may be interested in knowing that the GETPIXEL() command is not used. First of all, because it is far too slow for this function, and secondly because the colors it attempts to read from an image can be off. The beauty of this function is its speed and precision. Each pixel color is exact, for the algorithm which calculates the pixel color is the same algorithm which rendered the image in the first place.
This brings me nicely to the next item. Parameters.
There are three parameters available to the programer at the start of the ColorWheel function.
The first, as I've already mentioned, tells the computer to delete the png image and render it anew.
The second allows you to turn on and display, or turn off and not display, an "OK" button on the main color wheel screen.
The OK button allows the user to exit with his or her chosen color immediately from the colorwheel screen. If this parameter is set to FALSE, the user must exit the function by way of the Slider Screen (which is obtained by clicking the Right mouse button.) Changing the setting on this parameter will require rendering the ColorWheel image anew, so that the button is displayed on the static screen image.
The third parameter sets a delay timer which is used on the Slider Screen, used for the RGB incremental buttons on either side of each R, G, and B sliders. Increase or decrease this timer (which watches the system clock) to your liking. The delay can be turned off altogether for a swift and smooth slide. But this can make setting exact numbers difficult.
I have allowed within the function, a place to accommodate additional features. This area is duly marked by comments. One feature which I may implement, if I find its absence annoying, is a way to enter numerical RGB values directly from the keyboard. But that is a feature for a future version which I did not feel the need for presently, given the size of the function in its current form and the time I have spent on it. (This started out as a feature for my Animation Spreadsheet project, and I am anxious to get back to this main project.)
In the course of writing this function I learned some really interesting things regarding to the Color Wheels and their color locations on the three-dimensional color-cube containing all possible colors which our computers can display. My next project will be to type up a post on these interesting, wonderfully mind-twisty things. When I do, I will post it to this thread.
Cheers!
-CW