small fixes to data examples

This commit is contained in:
Daniel Shiffman
2013-05-31 14:57:17 -04:00
parent bedaac427b
commit 261ec7dbda
2 changed files with 17 additions and 15 deletions

View File

@@ -8,13 +8,13 @@
*
* Here is what the CSV looks like:
*
x,y,diameter,name
160,103,43.19838,Happy
372,137,52.42526,Sad
273,235,61.14072,Joyous
121,179,44.758068,Melancholy
x,y,diameter,name
160,103,43.19838,Happy
372,137,52.42526,Sad
273,235,61.14072,Joyous
121,179,44.758068,Melancholy
*/
// An Array of Bubble objects
Bubble[] bubbles;
// A Table object
@@ -41,7 +41,10 @@ void draw() {
void loadData() {
// Load CSV file into a Table object
// "header" option indicates the file has a header row
table = loadTable("data.csv","header");
table = loadTable("data.csv", "header");
TableRow r = table.getRow(2);
int val1 = r.getInt("y");
// The size of the array of Bubble objects is determined by the total number of rows in the CSV
bubbles = new Bubble[table.getRowCount()];
@@ -57,8 +60,7 @@ void loadData() {
// Make a Bubble object out of the data read
bubbles[rowCount] = new Bubble(x, y, d, n);
rowCount++;
}
}
}
void mousePressed() {
@@ -69,15 +71,15 @@ void mousePressed() {
row.setFloat("y", mouseY);
row.setFloat("diameter", random(40, 80));
row.setString("name", "Blah");
// If the table has more than 10 rows
if (table.getRowCount() > 10) {
// Delete the oldest row
table.removeRow(0);
table.removeRow(0);
}
// Writing the CSV back to the same file
saveTable(table,"data/data.csv");
saveTable(table, "data/data.csv");
// And reloading it
loadData();
}