p5.js中的noCanvas()函數用於刪除由p5.js創建的默認畫布。可用於不需要畫布的草圖。它不接受任何參數。
用法:
noCanvas()
參數:此函數不接受任何參數。
以下程序說明了p5.js中的noCanvas()函數:
例:
function setup() {
createCanvas(400, 300);
// Create buttons for creating
// and removing the canvas
createBtn = createButton("Create Canvas");
createBtn.position(30, 20);
createBtn.mouseClicked(createDrawArea);
removeBtn = createButton("Remove Canvas");
removeBtn.position(30, 50);
removeBtn.mouseClicked(removeDrawArea);
}
function removeDrawArea() {
// Wrap noCanvas() in a try-catch
// to prevent error in case there
// exists no canvas to remove
try {
noCanvas();
} catch (e) {
print("No canvas found to remove");
print(e);
}
}
function createDrawArea() {
// Create a canvas with the
// given dimensions
createCanvas(400, 300);
}
function draw() {
clear();
background("green");
textSize(20);
text("This is the canvas area", 50, 130);
text("Canvas height:" + height, 50, 150);
text("Canvas width:" + width, 50, 170);
}
輸出:
相關用法
- PHP dir()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
- p5.js hex()用法及代碼示例
- p5.js arc()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
- PHP next()用法及代碼示例
- PHP exp()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- p5.js nfs()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP each()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- p5.js value()用法及代碼示例
- PHP ord()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | noCanvas() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。