import java.awt.Point;
final static int N_POINTS_EACH= 13;
float scale = 0.25f;
ArrayList <PointSet> allpointsets;
int currentset = 0;
void settings() {
size(700, 500);
}
void setup() {
frameRate(60);
allpointsets = new ArrayList(); // processing doesn't recognize the <>
Table table = loadTable("points.csv", "header");
for ( TableRow tr : table.rows() ) {
allpointsets.add(new PointSet(tr));
}
//println(allpointsets.size());
}
void draw() {
background(0);
strokeWeight(5);
PointSet ps = allpointsets.get(currentset);
for ( Point p : ps.points ) {
// Java default double -> Processing default float
stroke(random(0,255),random(0,255),random(0,255));
point((float)p.getX()*scale, (float)p.getY()*scale );
}
currentset++;
if ( currentset>=allpointsets.size() ) currentset = 0;
}
void keyPressed(){ //changes the value of scale when the key is pressed.
if (key==','){
scale -= 0.01;
}
else if(key=='.'){
scale += 0.01;
}
}
class PointSet {
Point [] points;
PointSet( processing.data.TableRow row ) {
points = new Point[N_POINTS_EACH];
for (int i=0; i<N_POINTS_EACH; i++) {
int x = row.getInt( "x"+(i+1) ); // +1 because starting from "x1" in data
int y = row.getInt( "y"+(i+1) );
points[i] = new Point(x, y);
}
}
}
Hi,
Welcome to the community!
First of all, you should format your code by pressing Ctrl+T
in the Processing IDE then use the </>
button in the message editor on the forum.