saturation()
Color / Creating & ReadingDescription
Extracts the saturation value from a color (HSB mode).
Syntax
float saturation(color c)
Parameters
| Name | Type | Description |
|---|---|---|
| c | color | any color value |
Returns
floatRelated
Under the Hood
From Processing.h:
float saturation() const {
float mx=std::fmax(r,std::fmax(g,b));
float mn=std::fmin(r,std::fmin(g,b));
return mx==0 ? 0 : ((mx-mn)/mx)*100.f;
}
float saturation(color c);
Under the Hood
From Processing.cpp:
float PApplet::saturation(color c) {
unsigned int v = c.value;
float r = (v >> 16 & 0xFF) / 255.f;
float g = (v >> 8 & 0xFF) / 255.f;
float b = (v & 0xFF) / 255.f;
float mx = max(r, max(g, b));
float mn = min(r, min(g, b));
return (mx == 0 ? 0 : (mx - mn) / mx) * colorMaxS;
}