function
setup() {
createCanvas(600, 400);
textSize(18);
text(
"Click on the button to get the "
+
"values of the table as an object"
,
20, 20);
setBtn =
createButton(
"Get all table values"
);
setBtn.position(30, 40);
setBtn.mouseClicked(showTable);
table =
new
p5.Table();
setTableData();
}
function
setTableData() {
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
showTable() {
clear();
text(
"All the values are retrieved "
+
"using the getObject() method"
, 20, 20);
text(
"Below is the object representation "
+
"of the whole table"
, 20, 80);
let tableObject = table.getObject(
"Invention"
);
console.log(tableObject);
text(JSON.stringify(tableObject,
null
,
'\t'
), 20, 120);
}