saturation()

Color / Creating & Reading

Description

Extracts the saturation value from a color (HSB mode).

Syntax

float saturation(color c)

Parameters

NameTypeDescription
ccolorany color value

Returns

float

Related

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; }