hue()
Color / Creating & ReadingDescription
Extracts the hue value from a color (HSB mode).
Syntax
float hue(color c)
Parameters
| Name | Type | Description |
|---|---|---|
| c | color | any color value |
Returns
floatRelated
Under the Hood
From Processing.h:
float hue() const {
float rf_=r/255.f, gf_=g/255.f, bf_=b/255.f;
float mx=std::fmax(rf_,std::fmax(gf_,bf_));
float mn=std::fmin(rf_,std::fmin(gf_,bf_));
float d=mx-mn;
if (d==0) return 0;
float h = (mx==rf_) ? (gf_-bf_)/d : (mx==gf_) ? 2.f+(bf_-rf_)/d : 4.f+(rf_-gf_)/d;
h *= 60.f;
if (h < 0) h += 360.f;
return h;
}
float hue(color c);
Under the Hood
From Processing.cpp:
float PApplet::hue(color c){
unsigned int v=c.value;
float r=(v>>16&0xFF)/255.f,g=(v>>8&0xFF)/255.f,b=(v&0xFF)/255.f;
float mx=max(r,max(g,b)),mn=min(r,min(g,b)),d=mx-mn;
if(d==0)return 0;
float h=(mx==r)?(g-b)/d:(mx==g)?2+(b-r)/d:4+(r-g)/d;
h*=60;if(h<0)h+=360;return h/360.0f*colorMaxH;
}