Workshop: Using Data in p5.Embroider
Using p5.Embroider, we can use data imported from a csv file to create embroidered data representations.
1. Import .csv file
To do this, we need to create a table variable and load the data from the .csv into it.
let table;
function preload() {
table = loadTable('wind.csv', 'header');
}
The header argument indicates that the table has column headers so should be removed if it doesn't.
2. Access Data from Table
For this example, the structure of the csv file is as below.
We can use .getRows() and a for-loop to iterate through the rows of the table. Then, .getNum() can be used to access each value within the row. .getNum() takes either an index or the name of the column (e.g. .getNum(0) or .getNum('January'))
let tableRows = table.getRows();
for (let row of tableRows) {
for (let i=0; i<table.getColumnCount()-1; i++){
console.log(row.getNum(i));
}
}
