function
setup() {
createCanvas(500, 300);
textSize(18);
text(
"Click the button to modify"
+
" the table"
, 20, 20);
setBtn =
createButton(
"Change Status"
);
setBtn.position(30, 60);
setBtn.mouseClicked(modifyTableData);
table =
new
p5.Table();
table.addColumn(
"flight"
);
table.addColumn(
"status"
);
let row = table.addRow();
row.setString(
"flight"
,
"American Air"
);
row.setString(
"status"
,
"On Time"
);
row = table.addRow();
row.setString(
"flight"
,
"Lufthansa"
);
row.setString(
"status"
,
"On Time"
);
row = table.addRow();
row.setString(
"flight"
,
"United Air"
);
row.setString(
"status"
,
"Delayed"
);
showTable();
}
function
modifyTableData() {
for
(let r = 0; r < table.getRowCount(); r++) {
if
(table.getString(r,
"status"
) ==
"On Time"
)
table.setString(r,
"status"
,
"Delayed"
);
else
table.setString(r,
"status"
,
"On Time"
);
}
showTable();
}
function
showTable() {
clear();
text(
"The value is modified using the"
+
" setString() method"
, 20, 20);
for
(let c = 0; c < 2; c++) {
text(table.columns,
20 + 160 * c, 110);
}
for
(let r = 0; r < 3; r++) {
for
(let c = 0; c < 2; c++) {
text(table.getString(r, c),
20 + 160 * c,
140 + 20 * r);
}
}
}