function
setup() {
createCanvas(500, 300);
textSize(16);
tokensInput = createInput();
tokensInput.position(30, 40)
trimBtn =
createButton(
"Remove specified tokens"
);
trimBtn.position(30, 80);
trimBtn.mouseClicked(cleanTableData);
table =
new
p5.Table();
table.addColumn(
"subject"
);
table.addColumn(
"performance"
);
let newRow = table.addRow();
newRow.setString(
"subject"
,
"----Maths---"
);
newRow.setString(
"performance"
,
"-----Good==="
);
newRow = table.addRow();
newRow.setString(
"subject"
,
"-----English---"
);
newRow.setString(
"performance"
,
"__-Excellent--"
);
newRow = table.addRow();
newRow.setString(
"subject"
,
"-Science---"
);
newRow.setString(
"performance"
,
",,, ;OK;"
);
showTable();
}
function
cleanTableData() {
let tokensToRemove = tokensInput.value();
table.removeTokens(tokensToRemove,
'subject'
);
showTable();
}
function
showTable() {
clear();
for
(let r = 0; r < table.getRowCount(); r++)
for
(let c = 0; c < table.getColumnCount(); c++)
text(table.getString(r, c),
20 + c * 100,
140 + r * 20);
text(
"Enter the tokens that have to be"
+
" removed from the table values"
,
20, 20);
}