PDA

View Full Version : Select colors at run-time



Ñuño Martínez
11-11-2007, 08:15 PM
Well, I'm not sure about the subject, but here I go with my problem.

In the game I'm working is a board game that uses small RPG-style sprites. The colours for skin, hair and clothes are selected by the user. The program draws a dialog with lots of colours and the user select the ones he/she wants for his character.

The problem is that the sprite uses two colours for each part (bright and dark). Once the player selects a colour the program uses the next code to calculate the dark version:al_rgb_to_hsv (BrightR, BrightG, BrightB, @h, @s, @v);
v := v / 2;
al_hsv_to_rgb (h, s, v, @DarkR, @DarkG, @DarkB);
I know it's an ugly piece of code and I'm sure there are better ways to calculate this. Do you know any?

And also, where can I find a nice palette of colours for skins, hair and clothes to use in my program?

Thanks.

User137
12-11-2007, 04:41 PM
How about this:
DarkR:=BrightR/2; // div would be faster if you represent values as byte
DarkG:=BrightG/2;
DarkB:=BrightB/2;

Other than that more info would be needed, like used graphics API or contains of those 2 functions.

Ñuño Martínez
12-11-2007, 08:11 PM
Thanks for te reply.

Other than that more info would be needed, like used graphics API or contains of those 2 functions.The graphics API is Allegro.pas and the functions just translates a color definition from the Red-Green-Blue space to the Hue-Saturation-Value space and vice-versa.

Now I feel as dump. The R/2,G/2,B/2 is so obvious. :oops:

Anyway I was creative this morning and find another solution: create a simple palette with few colours, may be 16, 25 or 32, and set the bright-dark values in two arrays.

Thanks again.