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