The createSelect() function in p5.js is used to create a dropdown menu element in the DOM (Document Object Model) for taking input. The .value() method is used to get the selected option. This function includes the p5.dom library. Add the following syntax in the head section.
Note: This function requires the p5.dom library. So add the following line in the head section of the index.html file.
<script src=”https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js”>
</script>
Syntax:
createSelect(multiple)
or
createSelect(existing)
Parameters:
- multiple: It holds the state of input. Multiple if Ture, single if False.
- existing: It holds the object DOM select element.
Return Value: This function returns the value of an attribute in p5.Element format.
Example: This example uses a dropdown menu to change the background color from the given options.
// Create a variable for dropdown menu object var dropdown; function setup() { // Create a canvas createCanvas(400,400); // Create a dropdown menu object dropdown = createSelect(); // Position the dropdown menu dropdown.position(150,200); // Set options dropdown.option("orange"); dropdown.option("green"); dropdown.option("skyblue"); } function draw() { // Set the background-color as choosen // from the dropdown menu background(dropdown.value()); } |
Output:



Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Reference: https://p5js.org/reference/#/p5/createSelect
Recommended Posts:
- How to get the function name from within that function using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- D3.js | d3.map.set() Function
- D3.js easePolyOut Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- D3.js | d3.bisectLeft() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
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.


