Color selection

Hey everyone. I’m working on my user interface and toon maker. One of things I would like for my users to do is pick colors for their toon. How would one go about doing something like that?

Asking how to “add” the color into a box, I can figure out how to do everything else.

aka (example to get the idea out there, I know this code wont work)

color = 0
x = 0
y = 0
for color in range (00000000 to ffffffff):
  print color on (x,y)
  x = x + 1
  y = y + 1

I would use the PNMPainter class to paint a gradient palette, then convert that to a texture and draw it on screen. Then you detect a mouse click and deduce the color from the coordinates of the point clicked.

You have a 2D image but a color always has 3 components (minimum). Programs go around this by representing 2 dimensions in one image and 1 dimension in other, which changes according to the selection in the two-dimensional one. You could, of course, assume constant luminosity or constant saturation. Google for the function to convert between HSL and RGB or HSV and RGB.

If you don’t need arbitrary colors then you could also draw a palette in a grid, even easier.

Never used PNMPainter before… so not sure how use it. I’ll see how it works and try that idea.

Yea, I made a color patlette grid color image, but I’m hopping to keep the space down by using code instead.

RGB will work, its simple and only request 3 vales (red, green, blue), so it should be easy to make in code.


^ generate some thing like this, then you know what algorithm you used and you can read the values back.

I’d go for something like what Treeform is saying. If you can figure out a procedural way to generate a colour pallette, you can work out the colour backwards from a x/y value of the image. You might want to start out from one of the many javascript implementations of colour pickers.

Something to think about is whether or not you really need that many color selections. Do you really need to give the user every possible color combination or will 5-10 choices be sufficient? For instance, just giving the user the choice between the most basic colors - red, green, blue, orange, green, purple, black, white, etc.

discourse.panda3d.org/viewtopic.php?t=3199

Wow, thanks ynjh. Thats what I’m looking to do.

b1g4l:
I guess users don’t need the full color spec., but I wanted to give them the choice.