Skip to content

Instantly share code, notes, and snippets.

@witchica
Created November 28, 2019 14:28
Show Gist options
  • Save witchica/e1d2162cdc9eb49c59af47e47bcdef25 to your computer and use it in GitHub Desktop.
Save witchica/e1d2162cdc9eb49c59af47e47bcdef25 to your computer and use it in GitHub Desktop.
Light Level Visualisation
//table to store data
Table data;
void setup() {
//set the visualisation resoluton
size(4000, 2000);
//load the data file
data = loadTable("feeds.csv", "header");
//get the amount of rows and index
int amount = data.getRowCount();
int index = 0;
//set the white background, black stroke 2pt and no fill
background(255);
stroke(0);
strokeWeight(2);
noFill();
//begin visualisation
beginShape();
//loop through the rows
for(TableRow row : data.rows()) {
//get light level
int level = row.getInt("field1");
//get the x from the current index and y from the data (0, 1024) mapped to (height - 0)
float x = map(index, 0, amount, 0, width);
float y = map(level, 0, 1024, height, 0);
//set the stroke colour and plot the point
stroke(0);
vertex(x, y);
//increment index
index++;
}
//end the shape
endShape();
//save the visualisation and quit
saveFrame("data.png");
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment