Thursday, September 4, 2025
HomeLanguagesJavascriptp5.js | setBlue() Function

p5.js | setBlue() Function

The setBlue() function in p5.js is used to set the blue color value in RGB color mode. It sets the third value of RGB format.

Syntax:

setBlue(blue)

Parameters: The function accepts single parameter as mentioned above and described below:

  • blue: This parameter stores the new blue value.

Below programs illustrate the setBlue() function in p5.js:
Example-1: This example uses setBlue() function to set red value of RGB color format.




/* declare a variable to 
store the value of color*/
let backgroundColor;
  
function setup() {
    /* initialise the variable
    with RGB color format*/
    backgroundColor = color(13, 40, 0);
}
  
function draw() {
    // Create Canvas of a given size
  
    createCanvas(500, 500);
  
    // Use of setBlue function
    backgroundColor.setBlue(
      0 + 128 * cos(millis() / 1000));
  
    /* Pass the initialised 
    variable to background function*/
    background(backgroundColor);
  
    // Set text size
    textSize(30);
  
    // Set text color
    fill("white");
  
    // set text
    text("GeeksForGeeks", 125, 125);
  
}


Output:

Example 2: This example uses setBlue() function to set red value of RGB color format.




/* declare a variable
to store the value of color*/
let backgroundColor;
  
function setup() {
    /* initialise the variable
    with RGB color format*/
    backgroundColor = color(0, 0, 0);
}
  
function draw() {
    // Create Canvas of a given size
  
    createCanvas(540, 500);
  
    /* Use of setBlue function
    and initialise it to maximum*/
    backgroundColor.setBlue(255);
  
    /* Pass the initialised 
    variable to background function*/
    background(backgroundColor);
  
    // Set text size
    textSize(30);
  
    // Set text color
    fill("white");
  
    // set text
    text("GeeksForGeeks\n ", 135, 125);
    text(
      "A Computer Science Portal For Geeks"
      , 10, 155);
  
}


Output:

Reference:https://p5js.org/reference/#/p5.Color/setBlue

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS