createRadio()函數用於在DOM(文檔對象模型)中創建radio-button元素。 .option()方法用於設置收音機的選項。
此函數需要p5.dom庫。因此,在index.html文件的開頭部分添加以下行。
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.dom.min.js">
</script>
用法:
createRadio( divId )
參數:該函數接受單個參數divId,該參數分別保存創建的div和輸入字段的ID和名稱。
例:本示例根據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
radio.option('orange');
// Option 2 : skyblue
radio.option('skyblue');
// Option 3 : green
radio.option('green');
// Set the width
radio.style("width", "80px");
// Posotion 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
background(val);
}
輸出:
參考:https://p5js.org/reference/#/p5/createRadio
相關用法
- p5.js red()用法及代碼示例
- PHP pos()用法及代碼示例
- p5.js tan()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- p5.js sin()用法及代碼示例
- PHP key()用法及代碼示例
- p5.js cos()用法及代碼示例
- p5.js log()用法及代碼示例
- p5.js day()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js second()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
注:本文由純淨天空篩選整理自SujanDutta大神的英文原創作品 p5.js | createRadio() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。