p5.js hue() function

The hue() function in p5.js is used to extract the HSB and HSL hue value from a color or pixel array.
Syntax:
hue(c)
Parameters: This function accepts single parameter c which stores the p5.Color object, color components, or CSS color.
Below programs illustrate the hue() function in p5.js:
Example 1: This example uses hue() function to extract the HSB and HSL hue value from a color or pixel array.
| functionsetup() {      // Create Canvas of size 300*80     createCanvas(300, 80); }  functiondraw() {          // Set background color     background(220);          // Initialize color mode to HSB     colorMode(HSB, 255);      // Initialize the parameter     let c = color(0, 126, 100);          // Sets 'value' to 0     let value = hue(c);           // Set font size     textSize(16);          // Set font color     fill(color('red'));      // Display result     text("Hue Value is : "+ value, 50, 30); }  | 
Output:
Example 2: This example uses hue() function to extract the HSB and HSL hue value from a color and fill color value as grayscale integer value.
| functionsetup() {          // Create Canvas of size 300*180     createCanvas(300, 180); }  functiondraw() {          // Set background color     background(220);          // Initialize color mode to HSB     colorMode(HSB, 255);          // Initialize the parameter     let c = color(56, 126, 10);          // Sets 'value' to 56     let value = hue(c);           // Fill the hue value as grayscale     fill(value);          // Create rectangle     rect(50, 15, 35, 70);          // Display result     text("Value of Hue is : "+ value, 22, 110); }  | 
Output:
Reference: https://p5js.org/reference/#/p5/hue
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					



