p5.js saturation() function
The saturation() function in p5.js is used to extract the HSL and HSB saturation value from a color or pixel array.
Syntax:
saturation(c)
Parameters: ThIS function accepts single parameter c which stores the p5.Color object, color components, or CSS color.
Below programs illustrate the saturation() function in p5.js:
Example 1: This example uses saturation() function to extract the HSL and HSB saturation value from the pixel array.
function setup() {
createCanvas(300, 80);
}
function draw() {
background(220);
colorMode(HSL, 255);
let c = color(0, 126, 100);
let value = saturation(c);
textSize(16);
fill(color( 'red' ));
text( "Saturation Value is : "
+ int(value), 50, 30);
}
|
Output:
Example 2: This example uses saturation() function to extract the HSL and HSB saturation value from the pixel array and fill this as grayscale value.
function setup() {
createCanvas(300, 180);
}
function draw() {
background(220);
colorMode(HSB, 255);
let c = color(56, 126, 10);
let value = saturation(c);
fill(value);
rect(50, 15, 35, 70);
text( "Value of Saturation is : "
+ int(value), 22, 110);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/saturation
Last Updated :
11 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...