Lesson 40 – Arrays
“Flocking” simulation — actually, 100 drunks:
float pxArray[]; // declaration
float[] pyArray;
int nDrunks = 100;
void setup() {
size(400, 400);
pxArray = new float[nDrunks]; // ALLOCATION
pyArray = new float[nDrunks];
for (int i=0; i
A case where the arrays are set with specific values at the start:
float xPoints[] = {
280.0, 289.0, 134.0, 64.0, 151.0
};
float yPoints[] = {
74.0, 205.0, 260.0, 194.0, 61.0
};
void setup() {
size (400, 400);
smooth();
}
void draw() {
background(126);
beginShape();
for (int i=0; i<5; i++) {
float px = xPoints[i] + 30*noise(i + millis()/200.0);
float py = yPoints[i] + 30*noise(i + millis()/313.0);
vertex(px,py);
}
endShape(CLOSE);
}