I'm trying to find a way to convert from HSL to RGB but I seem to have problems finding the actual algorithm for it.
I found a segment of C++ code but even stranger is that it goes from 0-360 (like I thought it was supposed to do) even though in some editors it seems to cut off at 240.
Here is what I got from http://astronomy.swin.edu.au/~pbourke/colour/hsl/
COLOUR c2,sat,ctmp;
while (c1.h < 0)
c1.h += 360;
while (c1.h > 360)
c1.h -= 360;
if (c1.h < 120) {
sat.r = (120 - c1.h) / 60.0;
sat.g = c1.h / 60.0;
sat.b = 0;
} else if (c1.h < 240) {
sat.r = 0;
sat.g = (240 - c1.h) / 60.0;
sat.b = (c1.h - 120) / 60.0;
} else {
sat.r = (c1.h - 240) / 60.0;
sat.g = 0;
sat.b = (360 - c1.h) / 60.0;
}
sat.r = MIN(sat.r,1);
sat.g = MIN(sat.g,1);
sat.b = MIN(sat.b,1);
ctmp.r = 2 * c1.s * sat.r + (1 - c1.s);
ctmp.g = 2 * c1.s * sat.g + (1 - c1.s);
ctmp.b = 2 * c1.s * sat.b + (1 - c1.s);
if (c1.l < 0.5) {
c2.r = c1.l * ctmp.r;
c2.g = c1.l * ctmp.g;
c2.b = c1.l * ctmp.b;
} else {
c2.r = (1 - c1.l) * ctmp.r + 2 * c1.l - 1;
c2.g = (1 - c1.l) * ctmp.g + 2 * c1.l - 1;
c2.b = (1 - c1.l) * ctmp.b + 2 * c1.l - 1;
}
return(c2);
}
I want to convert it but I think threre is a better eay (since I only really need it for ONE conversion
h = 27, s = 240 or something more appropriate for skin tones)</0>
ID:147450
![]() May 21 2004, 12:58 pm (Edited on May 21 2004, 2:24 pm)
|
|
Holy crap, someone else at BYOND uses PSP? *gasps*
Anyway, MS Paint can also. Open it, and double-click any of the colors in the pallete, then click "Define Custom Colors >>." EDIT: By the way, that color dialog uses hue values 0-239. (240 values.) |
No, no. The problem is that in game I want to do some somewhat high level icon editing where primarily I have an icon (which I'm not sure is pure white or black) that will then become tinted to be the correct color.
On a related note as to how to draw the icon how would I add multiple shades, like for example the outline of the character would be slightly darker? |
You mean at runtime? Well, you can do I.Blend(rgb(0,0,0), ICON_MULTIPLY) to set all of the colours in an icon to black (where I is the /icon to affect). You can then set it to whatever colour by using ICON_ADD. For example, to set it to red: I.Blend(rgb(255,0,0), ICON_ADD).
As for outlines - if you already have an outline on the characters, just use icon.SwapColor() to swap from that colour to the colour you want it to be. If not, you can do an involved series of Blend()s and Shift()s to get an outline. Assuming your existing icon is I, you might do something like this: <code>var/icon/base=new(I) // Blacken it base.Blend(rgb(0,0,0),ICON_MULTIPLY) // Shift and blend to make an outlined version: var/icon/outline=new(base) outline.Blend(base.Shift(WEST,1)) outline.Blend(base.Shift(EAST,1)) outline.Blend(base.Shift(NORTH,1)) outline.Blend(base.Shift(SOUTH,1)) // Make it whatever colour (I've chosen yellow here) outline.Blend(rgb(255,255,0)) // Put the original icon on top of it outline.Blend(I,ICON_OVERLAY) // (If the above line doesn't work, try ICON_UNDERLAY instead; I'm not quite sure which way around it goes.)</code> What exactly are you trying to do here, anyway? If you're doing this in a game, be warned that icon operations are CPU-intensive and can generate extra network traffic (to send the resulting icons to the clients when the clients need to be able to see them). |
Anyway; RGB 247,216,167 is a decent light skin tone. Play around with those values until you find what you're looking for.