The red() function in p5.js is used to extract the red value from a color or pixel array.
Parameters: This function accepts single parameter c which stores the p5.Color object, color components, or CSS color.
Below programs illustrates the red() function in p5.js:
Example 1: This example uses red() function to extract the red value from the pixel array.
let c = color(67, 126, 255, 102);
let y = red(c);
"Red Value is : "
+ y, 50, 30);
Example 2: This example uses red() function to extract the red value from the pixel array and used as fill color.
let c = color(80, 126, 100, 34);
let value = red(c);
fill(value, 0, 0);
rect(50, 15, 35, 70);
"Value of red is : "
+ value, 22, 110);
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!