ID:2232714
 
(See the best response by Ease.)
So I have certain characters that I want displayed in 6 different colors depending on your faction. I have thought of some ideas on doing this but haven't done anything like it before so my idea is:

first I need to find out the colors in need of change,
I'll loop through all colors in the palette and if they are similar enough I will multiply them by a certain value that will achieve the desired result

is there a better alternative?? or is there some integrated proc in byond??
Best response
I take it you have a humanoid wearing clothes/something, and it's only the clothes/something that you want to colour?

Personally I'd make a base of a naked humanoid: maybe even just the head/hands/visible flesh.

Then I'd make another icon for the clothes, and I'd try to make them as greyscale as possible.

Then on creation of the mob/humanoid, I'd blend the clothes separately and add them as an overlay to the mob.

So it'd look something like this
obj/Clothes
icon = 'Clothes.dmi'
mob/Tutor
New()
..()
var/obj/Clothes/clothes = new()
var/icon/I = new(clothes.icon)
I.Blend(rgb(r,g,b),ICON_MULTIPLY)
clothes.icon = I
src.overlays+=clothes


Though I'm at work so I can't compile and run to test.
Thx for your help I've though of it as a last resort because it will take much time to add the clothes and will also increase src use.

I'm thinking if I could somehow create a mask and then change color of the masked are but that may not be feasible or efficient.
mob/Tutor
New()
..()
var/icon/I = new('mask.dmi')
I.Blend(rgb(r,g,b),ICON_MULTIPLY)
var/icon/srcI = new(src.icon)
srcI.Blend(I,ICON_MULTIPLY)
src.icon = srcI


Though creating the mask (a grey blocked out outline of the area you want to colour) is going to be about as much effort as creating the separate clothes icon.
Yeah I was thinking of creating the mask proceduraly by finding the pixels with similar colors as the color that I want changed. I've already implemented a similar color algorithm (using CIE94) but the whole thing is not that efficient so I'll customly add the cloth parts in need of changing color separately and adjust the color var.

Thx for the help :)
You could use atom.color instead of Blend() and it would be dramatically less resource intensive. There's also MapColors() which is intensive like Blend() but provides matrix-type access to an icon's colors.
Yeah I'll definitely use color, tried both methods myself and it really is better
There's no reason to use MapColors since you can just use a color matrix and have the same result.