p5.js中p5.TableRow的getNum()方法用於從表行的給定列中檢索Float值。可以通過列ID或列名指定該列。
用法:
getNum( column )
參數:此方法接受如上所述和以下描述的單個參數:
- column:它是一個字符串或數字,表示列的名稱或列的ID。
返回值:此方法返回從表的給定列檢索的Floating值。
以下示例說明了p5.js中的getNum()方法:
例:
Javascript
function setup() {
createCanvas(600, 300);
textSize(18);
text("Click on the button to get " +
"all the values in the table",
20, 20);
setBtn =
createButton("Get all table values");
setBtn.position(30, 40);
setBtn.mouseClicked(showTable);
// Create the table
table = new p5.Table();
setTableData();
}
function setTableData() {
// Add 5 columns and rows to the table
for (let i = 0; i < 5; i++) {
table.addColumn("Column " + i);
table.addRow();
}
for (let r = 0; r < 5; r++) {
for (let c = 0; c < 5; c++) {
// Set the value at the given
// column and row of the table
table.set(r, c, r * 100 + c);
}
}
}
function showTable() {
clear();
text("The values of the table are " +
"retrieved using the getNum() method",
20, 20);
// Show all the columns present
for (let c = 0; c < 5; c++) {
text(table.columns,
20 + 100 * c, 80);
}
// Show all the rows currently
// present in the table
for (let r = 0; r < 5; r++) {
// Get the row of the table
let tableRow = table.rows[r];
for (let c = 0; c < 5; c++) {
// Get the numerical value at
// the given column of the row
text(tableRow.getNum(c),
20 + 100 * c,
120 + 20 * r);
}
}
}
輸出:
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
相關用法
- p5.js Table getNum()用法及代碼示例
- Lodash _.method()用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toString()用法及代碼示例
- Javascript Number.isInteger( )用法及代碼示例
- Javascript Number.isFinite()用法及代碼示例
- Javascript toFixed()用法及代碼示例
- Javascript toPrecision()用法及代碼示例
- JavaScript Math abs()用法及代碼示例
- JavaScript Math sqrt()用法及代碼示例
- JavaScript Math floor()用法及代碼示例
- Javascript toExponential()用法及代碼示例
- JavaScript Math pow()用法及代碼示例
- JavaScript Math trunc()用法及代碼示例
- JavaScript Math exp()用法及代碼示例
- JavaScript Math log()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.TableRow getNum() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。