saveTable()函數用於將p5.Table對象保存到文件中。所保存文件的格式可以定義為函數的參數。默認情況下,它保存帶有逗號分隔值的文本文件,但是,可以使用它來保存它,或者使用using-tab separated-values生成HTML表。
用法:
saveTable( Table, filename, options )
參數:此函數接受上述和以下所述的三個參數:
- Table:這是一個p5.Table對象,將保存到文件中。
- filename:它指定用作已保存文件的文件名的字符串。
- options:它是一個字符串,表示要保存的表的格式。它可以是使用逗號分隔值保存表的“csv”,使用製表符分隔值保存表的“tsv”或生成HTML表的“html”。它是一個可選參數。
下麵的示例說明了p5.js中的saveTable()函數:
例:
function setup() {
createCanvas(600, 300);
textSize(20);
text("Click on the button below to "
+ "save the Table Object", 20, 20);
text("Select the output format:", 20, 60);
// Create radio button for choosing
// file format to save the table
radio = createRadio();
radio.position(30, 80);
radio.option('csv');
radio.option('tsv');
radio.option('html');
// Create a button for saving the Table object
saveBtn = createButton("Save Table to file");
saveBtn.position(30, 120);
saveBtn.mousePressed(saveFile);
// Create the table for saving to file
table = new p5.Table();
table.addColumn('Invention');
table.addColumn('Inventors');
let tableRow = table.addRow();
tableRow.setString('Invention', 'Telescope');
tableRow.setString('Inventors', 'Galileo');
tableRow = table.addRow();
tableRow.setString('Invention', 'Steam Engine');
tableRow.setString('Inventors', 'James Watt');
tableRow = table.addRow();
tableRow.setString('Invention', 'Radio');
tableRow.setString('Inventors', 'Guglielmo Marconi');
}
function saveFile() {
// Get the output format selected
// from the radio buttons
outputFormat = radio.value();
// Save the table to file with the given format
saveTable(table, 'tableOutput', outputFormat);
}
輸出:
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5/saveTable
相關用法
- p5.js tan()用法及代碼示例
- PHP cos( )用法及代碼示例
- p5.js sin()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP abs()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- CSS hsl()用法及代碼示例
- p5.js int()用法及代碼示例
- p5.js str()用法及代碼示例
- p5.js hue()用法及代碼示例
- PHP each()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | saveTable() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。