P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Color
:
RGBtoHSB()
author:
Prometh
[+]
,
Submitted: 12.02.03 12p
• Last Edit: 12.02.03 1p
Color.RGBtoHSB = function(r,g,b) { var hsb = new Object(); hsb.b = Math.max(Math.max(r,g),b); var min = Math.min(Math.min(r,g),b); hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - min)/hsb.b); hsb.b = Math.round((hsb.b /255)*100); hsb.h = 0; if((r==g) && (g==b)) hsb.h = 0; else if(r>=g && g>=b) hsb.h = 60*(g-b)/(r-b); else if(g>=r && r>=b) hsb.h = 60 + 60*(g-r)/(g-b); else if(g>=b && b>=r) hsb.h = 120 + 60*(b-r)/(g-r); else if(b>=g && g>=r) hsb.h = 180 + 60*(b-g)/(b-r); else if(b>=r && r>=g) hsb.h = 240 + 60*(r-g)/(b-g); else if(r>=b && b>=g) hsb.h = 300 + 60*(r-b)/(r-g); else hsb.h = 0; hsb.h = Math.round(hsb.h); return hsb; }
usage
// This is a cleaned up version of Luzifer Altenberg's script. He gets the most credit // You can compare these values to those produced in the Photoshop Color Picker r = 255; g = 50; b = 120; hsb = RGBtoHSB(r,g,b); trace(hsb.h); // outputs a scale of 0-360 (degrees) trace(hsb.s); // outputs a scale of 0-100 (percent) trace(hsb.b); // same as above
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@