Author Topic: Custom Color Wheel  (Read 8708 times)

Offline CW

  • Mr. Polyvector
  • ***
  • Posts: 155
    • View Profile
Custom Color Wheel
« on: 2013-Mar-25 »
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     

« Last Edit: 2013-Mar-27 by CW »

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2537
    • View Profile
Re: Custom Color Wheel
« Reply #1 on: 2013-Mar-25 »
Very handy, for any situation that requires a colour selection. Thank you for sharing!  :good:
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1751
    • View Profile
    • Homepage
Re: Custom Color Wheel
« Reply #2 on: 2013-Mar-25 »
Wish I had that one four years ago, thanks :-)
I ended up just doing a simple polyvector thing with a different color in each corner and let GLBasic interpolate the rest but this is much better looking and exact.

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: Custom Color Wheel
« Reply #3 on: 2013-Mar-25 »
Thanks for sharing that CW, I can see a few uses for that coming up  =D =D

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4110
    • View Profile
    • Portfolio
Re: Custom Color Wheel
« Reply #4 on: 2013-Mar-25 »
Looks really interesting, nice read!

I didn´t give a try yet, but 2 things come to mind (which might already be there :-[):
- numerical enter (ye in case it is used more into a technical app)
- the yellow color wheel (ye in case it is for an art app)




Offline CW

  • Mr. Polyvector
  • ***
  • Posts: 155
    • View Profile
Re: Custom Color Wheel
« Reply #5 on: 2013-Mar-26 »
Thank you, everyone, for the nice words.  =D

Hi Erico.

A way to enter numerical values will be the next improvement. You mentioned a yellow-wheel. I have no background in art, so can you please tell me about that?

Thanks!
-CW

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4110
    • View Profile
    • Portfolio
Re: Custom Color Wheel
« Reply #6 on: 2013-Mar-26 »
It is a color wheel that does not have white, I can´t seem to find the official name (but in a BR book here).
But it is like these here:
http://emptyeasel.com/2007/03/16/using-the-color-wheel-color-theory-tips-for-artists-and-painters/

It does not have white or black.
That is good for painting.

Offline CW

  • Mr. Polyvector
  • ***
  • Posts: 155
    • View Profile
Re: Custom Color Wheel
« Reply #7 on: 2013-Mar-26 »
I see what you mean. I could possibly adapt this method to displaying such a color wheel, but it wouldn't be easy.

It seems to me that there are three, and possibly more, fundamentally different types of color wheels. The one I did is based on a mixing of RGB colors, where Yellow is the opposite of blue and where all of the colors together form white. That is good for computer art.

Then there is the type of color wheel based on the primary (paint) colors, like the wheel you linked to, where yellow is the opposite of purple and where all of the colors together combine to form brown.

Then there is the type of color wheel based on light, where all of the colors together combine to form white, but where the colors, being of the light spectrum, have no opposites (unless the 'opposite' of a wavelength is that which combines to form no light at all.) Such a wheel (or rainbow?) could be useful in optics, I suspect.

Rather than expand on the current color wheel to include a yellow-wheel, I think it would be better to create an entirely different function for that, using some sort of reference matrix to convert from RGB format to RYB. Such a matrix probably exists, but it is beyond my current abilities to devise such a thing. Still, it could be a really neat learning challenge. The color wheel would display mixtures of primary colors with graduations of white and black along the radii to obtain pinks (and/or darker hues). The output would be listed as (R#,Y#,B#) instead of RGB. Anyway, that is a project for another day. I have other things to work on before then, but I hereby freely share my code and methods with anyone who thinks it would be an interesting project to tackle.

-CW
« Last Edit: 2013-Mar-26 by CW »

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4110
    • View Profile
    • Portfolio
Re: Custom Color Wheel
« Reply #8 on: 2013-Mar-26 »
You are totally right on the 3 methods of color sets. :O
I wont even bother you with LAB colors ;)

It is just I find what you did really soo amazing :good:

Offline CW

  • Mr. Polyvector
  • ***
  • Posts: 155
    • View Profile
Re: Custom Color Wheel
« Reply #9 on: 2013-Mar-26 »
LOL, well Thank You!  :booze:
-CW

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1751
    • View Profile
    • Homepage
Re: Custom Color Wheel
« Reply #10 on: 2013-Mar-26 »
What did you use for compressing the files? I can't seem to unpack all the files in the archive.

Offline CW

  • Mr. Polyvector
  • ***
  • Posts: 155
    • View Profile
Re: Custom Color Wheel
« Reply #11 on: 2013-Mar-26 »
I used the GL-Basic zip utility, found under the Tools tab to zip the folder. But the text on the utility is in German (two words). I don't know what it says, but it seemed to work.

Thank you for letting me know that you are having problems unzipping the folder. If people can't unpack it, that is very bad. Did you try right-clicking on it? or Left-Click Extract All? If those option are not available to you I will hunt down a different compression utility and redo the upload. I wonder if the fact that I'm running a 64-bit system is causing problems with the GLBasic zip. Has anyone else had trouble with the format I used? If so, don't be polite. Please let me know!

-CW

PS. At the end of this post is attached ColorWheel.7z, compressed using 7-Zip, a free utility which can be downloaded at:
http://download.cnet.com/7-Zip/3000-2250_4-10045185.html
(Note that I have removed the 7zip file. Now that the problem is solved, that version is redundant.)

I can't explain why you wouldn't be able to unpack some of the files in the folder unless something was corrupted during the compression process. (Access conflict? Don't know.) anyway, I went back and compressed it using the GL-Basic zip utility again and updated the file attached to my original post. Please leave feedback about success/failure in opening my program.
« Last Edit: 2013-Mar-27 by CW »

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3338
  • Integrated Brain
    • View Profile
Re: Custom Color Wheel
« Reply #12 on: 2013-Mar-27 »
Hi CW thanks a lot for this Code, sometime ago I needed something similar.... I think for the App 3D I have in mind this comes very very handy... (whit your permission I will add in my code)

And the UI it's very nice  :good:


Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1751
    • View Profile
    • Homepage
Re: Custom Color Wheel
« Reply #13 on: 2013-Mar-27 »
I used 7-zip for opening and extracting. The gbas file was 0 bytes, some other files I got the message "compression not supported" Mabe it was cut off while uploading because the new file was 200 kb larger now. However the gbas file is still 0 bytes and three other files has "unsupported compression". If I use the windows XP unpack function I get "unexpected end of file". Most likely your upload is not complete. Compare the size of the file on the server with your file before uploading, are they the same size? Mabe remove the .exe-file from the file to make it smaller?

Tried Winrar now too, no luck.

Played with making my own colorwheel, used setpixel to display it and it is much faster than I was expecting. I get almost realtime display of a 300 pixel diameter disc following the mouse around. And I thought that command would be sooo slow according to what people keep saying :-) Ok, if you would expand that to the whole display...
« Last Edit: 2013-Mar-27 by Moru »

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: Custom Color Wheel
« Reply #14 on: 2013-Mar-27 »
Similar problems like Moru was having in that in the 7z file the .gbas was 0 bytes. Had no errors extracting though & the exe works fine.

Win7 x64 with 7z 9.20 x64.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)