p5.js | setGreen() Function
Last Updated :
23 Apr, 2019
The setGreen() function in p5.js is used to set the green color value in RGB color mode. It sets the second value of RGB format.
Syntax:
setGreen(green)
Parameters: The function accepts single parameter as mentioned above and described below:
- green: This parameter stores the new green value.
Below programs illustrate the setGreen() function in p5.js:
Example-1: This example uses setGreen() function to set red value of RGB color format.
let backgroundColor;
function setup() {
backgroundColor =
color(13, 0, 150);
}
function draw() {
createCanvas(500, 500);
backgroundColor.setGreen(
0 + 128 * cos(millis() / 1000));
background(backgroundColor);
textSize(30);
fill( "white" );
text( "GeeksForGeeks" , 125, 125);
}
|
Output:
Example-2: This example uses setGreen() function to set red value of RGB color format.
let backgroundColor;
function setup() {
backgroundColor =
color(0, 0, 0);
}
function draw() {
createCanvas(540, 500);
backgroundColor.setGreen(255);
background(backgroundColor);
textSize(30);
fill( "green" );
text( "GeeksForGeeks\n " , 135, 125);
text(
"A Computer Science Portal For Geeks"
, 10, 155);
}
|
Output:
Reference:https://p5js.org/reference/#/p5.Color/setGreen
Share your thoughts in the comments
Please Login to comment...