p5.js createColorPicker() Function
Last Updated :
16 Aug, 2023
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.
var color_picker;
function setup() {
createCanvas(400,400);
color_picker = createColorPicker( "green" );
}
function draw() {
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...