Results 1 to 3 of 3

Thread: Select colors at run-time

  1. #1

    Select colors at run-time

    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:[pascal]al_rgb_to_hsv (BrightR, BrightG, BrightB, @h, @s, @v);
    v := v / 2;
    al_hsv_to_rgb (h, s, v, @DarkR, @DarkG, @DarkB);[/pascal]
    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.
    No signature provided yet.

  2. #2

    Select colors at run-time

    How about this:
    [pascal]DarkR:=BrightR/2; // div would be faster if you represent values as byte
    DarkG:=BrightG/2;
    DarkB:=BrightB/2;[/pascal]

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

  3. #3

    Select colors at run-time

    Thanks for te reply.
    Quote Originally Posted by User137
    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. ops:

    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.
    No signature provided yet.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •