Convert RGB to HSV
Richmond Mathewson
richmondmathewson at gmail.com
Sun Jul 5 09:27:08 EDT 2009
New version:
http://mathewson.110mb.com/FILEZ/COLORNAMER.rev.zip
now showing RGB, HSV and HSL
actually the code is dead easy once you can cope with all the brackets:
used this in a listField full of colorNames:
on mouseDown
get the clickText
put the clickText into fld "SELECT"
set the backgroundColor of fld "KNAMES" to the clickText
set the backgroundColor of grc "SAMPLE" to the clickText
end mouseDown
on mouseUp
put "RGB " & the mouseColor into fld "fRGB"
put the mouseColor into FRGB
put item 1 of FRGB into ARR
put item 2 of FRGB into GEE
put item 3 of FRGB into BEE
put max(FRGB) into maxRGB
put min(FRGB) into minRGB
if maxRGB = minRGB then
put 0 into ACHE
else
if maxRGB = ARR then
put ((60 * ((GEE - BEE) / (maxRGB - minRGB)) + 360) mod
360) into ACHE
end if
if maxRGB = GEE then
put (60 * ((BEE - ARR) / (maxRGB - minRGB)) + 120) into ACHE
end if
if maxRGB = BEE then
put (60 * ((ARR - GEE) / (maxRGB - minRGB)) + 240) into ACHE
end if
end if
if maxRGB = minRGB then
put 0 into ESS
else
put (0.5 * (maxRGB + minRGB)) into ELL
if ELL <= 0.5 then
put ((maxRGB - minRGB) / (maxRGb + minRGB)) into ESS
end if
if ELL > 0.5 then
put ((maxRGB - minRGB) / (2 - (maxRGb + minRGB))) into ESS
end if
end if
put maxRGB into VEE
put "HSV " & ACHE & "," & ESS & "," & VEE into fld "fHSV"
put "HSL " & ACHE & "," & ESS & "," & ELL into fld "fHSL"
set the backgroundColor of fld "KNAMES" to WHITE
end mouseUp
love Richmond.
More information about the use-livecode
mailing list