ID:133925
 
Possibly in a future release, the ability to define an icon's Hue, Sat, and Lum, like we can it's RGB, with the rgb() proc.
Body wrote:
Possibly in a future release, the ability to define an icon's Hue, Sat, and Lum, like we can it's RGB, with the rgb() proc.

I'm not sure how you'd apply this, because right now RGB is mostly applied to an icon by adding, subtracting, or multiplying.

Lummox JR
In response to Lummox JR
Hue sat and lum are done in numerics like RGB so couldn't it work on the same principle?
In response to Body
My sd_procs library includes two procs to convert between RGB and HSL values.
hsl2rgb(hue, sat, lgh, scale = 240)
        Returns the RRGGBB format of an HSL color.

        ALTERNATE FORMAT:
                hsl2rgb(HSL, scale)
        ARGS:
                hue             - hue
                sat             - saturation
                lgh             - light/dark
                HSL             - a hex string in format HHSSLL where:
                                                HH = Hue
                                                SS = Saturation
                                                LL = light
                scale   - high end of the HSL values. Some programs (like BYOND Dream Maker)
                                        use 240, others use 255. The H {0-360}, S {0-100}, L {0-100}
                                        scale is not supported.
                                        DEFAULT: 240
        RETURNS:
                RGB color string in RRGGBB format.

rgb2hsl(red, grn, blu, scale = 240)
        Returns the HSL color string of an RGB color

        ALTERNATE FORMAT:
                rgb2hsl(RGB, scale)
        ARGS:
                red             - red componant {0-255}
                grn             - green componant {0-255}
                blu             - blue componant {0-255}
                RGB             - a hex string in format RRGGBB
                scale   - high end of the HSL values. Some programs (like BYOND Dream Maker)
                                        use 240, others use 255. The H {0-360}, S {0-100}, L {0-100}
                                        scale is not supported.
                                        DEFAULT: 240
        RETURNS:
                HHSSLL color string


You can use "#[hsl2rgb(hue, sat, lgh)]" anywhere that you could use rgb(red, grn, blu). For example:
    I.Blend("#[hsl2rgb(0, 240, 30)]")

has the same effect as
    I.Blend(rgb(40,0,0))
You can achieve this with the new icon.MapColors proc in 4.0.

I've cooked this up, and it seems to work fine as far as I can tell. Just make calls to icon.SetBrightness, icon.SetSaturation, icon.OffsetColors, and icon.RotateHue to modify an icon.

// http://www.graficaobscura.com/matrix/index.html

icon
var/const
rwgt = 0.3
gwgt = 0.59
bwgt = 0.11
pi = 3.14159265

proc
TransformRGB(list/matrix)
src.MapColors(matrix[1][1], matrix[1][2], matrix[1][3], \
matrix[2][1], matrix[2][2], matrix[2][3], \
matrix[3][1], matrix[3][2], matrix[3][3], \
matrix[4][1], matrix[4][2], matrix[4][3])

SetBrightness(rscale, gscale, bscale) // Think this is the same as the existing SetIntensity
var/list/matrix = list(list(rscale, 0, 0, 0), \
list( 0, gscale, 0, 0), \
list( 0, 0, bscale, 0), \
list( 0, 0, 0, 1))
src.TransformRGB(matrix)

SetSaturation(s) // s of 0 will result in grayscale
var/list/matrix = list(list((1-s)*rwgt + s, (1-s)*rwgt, (1-s)*rwgt, 0), \
list( (1-s)*gwgt, (1-s)*gwgt + s, (1-s)*gwgt, 0), \
list( (1-s)*bwgt, (1-s)*bwgt, (1-s)*bwgt + s, 0), \
list( 0, 0, 0, 1))
src.TransformRGB(matrix)

OffsetColors(roffset, goffset, boffset)
var/list/matrix = list(list( 1, 0, 0, 0), \
list( 0, 1, 0, 0), \
list( 0, 0, 1, 0), \
list(roffset, goffset, boffset, 1))
src.TransformRGB(matrix)

RotateHue(rot) // rot in degrees, between 0 and 360
var
mag
xrs
xrc
yrs
yrc
zrs
zrc
var/list/matrix = IdentityMatrix()
mag = sqrt(2)
xrs = 1/mag
xrc = 1/mag
matrix = XRotateMatrix(matrix, xrs, xrc)
mag = sqrt(3)
yrs = -1/mag
yrc = sqrt(2)/mag
matrix = YRotateMatrix(matrix, yrs, yrc)
zrs = r_sin(rot*pi/180)
zrc = r_cos(rot*pi/180)
matrix = ZRotateMatrix(matrix, zrs, zrc)
matrix = YRotateMatrix(matrix, -yrs, yrc)
matrix = XRotateMatrix(matrix, -xrs, xrc)
src.TransformRGB(matrix)

proc // All of these might/probably already exist in someones' libraries
r_sin(rads)
return sin(rads*57.2957795)

r_cos(rads)
return cos(rads*57.2957795)

IdentityMatrix()
return list(list(1, 0, 0, 0), \
list(0, 1, 0, 0), \
list(0, 0, 1, 0), \
list(0, 0, 0, 1))

MatrixMultiply(list/a, list/b)
var
x
y
list/newmatrix[4][4]
for(y = 1, y <= 4, y++)
for(x = 1, x <= 4, x++)
newmatrix[y][x] = b[y][1] * a[1][x] \
+ b[y][2] * a[2][x] \
+ b[y][3] * a[3][x] \
+ b[y][4] * a[4][x]
return newmatrix

XRotateMatrix(list/matrix, rs, rc)
var/list/mmatrix = list(list(1, 0, 0, 0), \
list(0, rc, rs, 0), \
list(0, -rs, rc, 0), \
list(0, 0, 0, 1))
return MatrixMultiply(mmatrix, matrix)

YRotateMatrix(list/matrix, rs, rc)
var/list/mmatrix = list(list(rc, 0, -rs, 0), \
list( 0, 1, 0, 0), \
list(rs, 0, rc, 0), \
list( 0, 0, 0, 1))
return MatrixMultiply(mmatrix, matrix)

ZRotateMatrix(list/matrix, rs, rc)
var/list/mmatrix = list(list( rc, rs, 0, 0), \
list(-rs, rc, 0, 0), \
list( 0, 0, 1, 0), \
list( 0, 0, 0, 1))
return MatrixMultiply(mmatrix, matrix)


Example usage:
mob
icon = 'testicon.dmi'
verb
MakeMeGrey()
var/icon/i = new(src.icon)
i.SetSaturation(0)
src.icon = i
FlipColors()
var/icon/i = new(src.icon)
i.RotateHue(120)
src.icon = i
In response to Shadowdarke
I completely forgot to search the demos and libs for this sort of thing. My mistake guys. It isn't that I thought BYOND was in dire need of this proc but I figured somewhere down the line it wouldn't hurt to put it in. It could become useful to someone eventually, (obviously since someone has already made a proc for it) so I just figured I'd suggest it. Thanks for the responces guys.