Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

p5.js | createRadio() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The createRadio() function is used to create a radio-button element in the DOM (Document Object Model). The .option() method is used to set the options for the radio. 
This function requires p5.dom library. So add the following line in the head section of the index.html file. 


createRadio( divId )

Parameters: This function accepts single parameter divId which holds the id and name of the created div and input field respectively.
Example: This example changes the background color according to the selected option of the radio-button.


// Create a variable for radio-button object
var radio;
function setup() {
    // Create a canvas
    createCanvas(400, 400);
    // Create a radio-button object
    // and set options
    radio = createRadio();
    // Option 1 : orange
    // Option 2 : skyblue
    // Option 3 : green
    // Set the width"width", "80px");
    // Position the radio-button object
    radio.position(160, 200);
function draw() {
    // Get the value of the radio-button
    var val = radio.value();
    // Set the background-color



My Personal Notes arrow_drop_up
Last Updated : 26 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials