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.

filter_none

edit
close

play_arrow

link
brightness_4
code

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
}                    

chevron_right


Output:

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

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.