Saturday, September 6, 2025
HomeLanguagesJavascriptp5.js createColorPicker() Function

p5.js createColorPicker() Function

The createColorPicker() function in p5.js is used to create a color-picker element in the DOM (Document Object Model) for taking input color. The .color() method is used to get the currently chosen color. This function includes the p5.dom library. Add the following syntax in the head section.

Syntax:

createColorPicker( value )

Parameters: This function accepts single parameter value which holds the default color of color-picker.

Example: This example uses the color-picker object to set the background-color.




// Create a variable for color-picker object
var color_picker;
  
function setup() {
    
    // Create a canvas
    createCanvas(400,400);
      
    // Create a color-picker object 
    color_picker = createColorPicker("green");
}
  
function draw() {
      
    // Set the background-color as
    // chosen by the color-picker
    background(color_picker.color());
}                    


Output:

  • Before choose the color:
  • Choose the color from color picker:
  • After selecting the color:

Reference: https://p5js.org/reference/#/p5/createColorPicker

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!
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS