// Bevry, rectangles on random walk

int num = 4000;
int range = 20;

float[] ax = new float[num];
float[] ay = new float[num];


void setup()
{
size(600, 600);
for(int i=0; i<num; i++) {
ax[i] = 300;
ay[i] = height/2;
}
framerate(15);
}

void loop()
{
background(255);

// Shift all elements 1 place to the left
for(int i=1; i<num; i++) {
ax[i-1] = ax[i];
ay[i-1] = ay[i];
}

// Put a new value at the end of the array
ax[num-1] += random(-range, range);
ay[num-1] += random(-range, range);

// Constrain all points to the screen
ax[num-1] = constrain(ax[num-1], 0, width);
ay[num-1] = constrain(ay[num-1], 0, height);

// Draw a rect representing each move
for(int i=1; i<num; i++) {
float val = float(i)/num * 204.0 + 10;
fill(255,0,0,num-i);
rect(ax[i-1], ay[i-1], 5, 10);
}
}