function
setup() {
createCanvas(600, 300);
textSize(18);
text(
"Click on the button to get the "
+
"specific string value of the table"
,
20, 20);
text(
"Enter row and column"
, 20, 60);
rowInp = createInput();
rowInp.position(30, 80);
rowInp.size(30, 20);
colInp = createInput();
colInp.position(70, 80);
colInp.size(30, 20);
setBtn =
createButton(
"Get value at row and column"
);
setBtn.position(30, 110);
setBtn.mouseClicked(getValueAt);
table =
new
p5.Table();
setTableData()
}
function
setTableData() {
table.addColumn(
'Waterfall'
);
table.addColumn(
'Height'
);
let tableRow = table.addRow();
tableRow.setString(
'Waterfall'
,
'Angel Falls'
);
tableRow.setString(
'Height'
,
'979 metres'
);
tableRow = table.addRow();
tableRow.setString(
'Waterfall'
,
'Tugela Falls'
);
tableRow.setString(
'Height'
,
'948 metres'
);
tableRow = table.addRow();
tableRow.setString(
'Waterfall'
,
'Tres Hermanas Falls'
);
tableRow.setString(
'Height'
,
'914 metres'
);
}
function
getValueAt() {
clear();
let rowToGet = int(rowInp.value());
let colToGet = int(colInp.value());
if
(rowToGet < table.getRowCount() &&
colToGet < table.getColumnCount()) {
text(
"The value at row "
+ rowToGet +
" and column "
+ colToGet +
" is:"
,
20, 160);
text(table.getString(rowToGet, colToGet),
20, 180);
}
else
text(
"Please enter correct row and "
+
"column values"
, 20, 160);
text(
"Click on the button to get the "
+
"specific string value of the table"
,
20, 20);
text(
"Enter row and column"
, 20, 60);
}