function
setup() {
createCanvas(500, 200);
textSize(16);
getColBtn = createButton(
"Get Column Values"
);
getColBtn.position(30, 50);
getColBtn.mouseClicked(getCols);
text(
"Click on the button to get column values"
, 20, 20);
table =
new
p5.Table();
table.addColumn(
"author"
);
table.addColumn(
"language"
);
let newRow = table.addRow();
newRow.setString(
"author"
,
"Dennis Ritchie"
);
newRow.setString(
"language"
,
"C"
);
newRow = table.addRow();
newRow.setString(
"author"
,
"Bjarne Stroustrup"
);
newRow.setString(
"language"
,
"C++"
);
}
function
getCols() {
author_col = table.getColumn(
"author"
);
text(
"Column author: "
, 20, 100);
for
(let i = 0; i < author_col.length; i++) {
text(author_col[i], 170 + i * 120, 100);
}
language_col = table.getColumn(
"language"
);
text(
"Column language: "
, 20, 120);
for
(let i = 0; i < language_col.length; i++) {
text(language_col[i], 170 + i * 120, 120);
}
}