22 lines
451 B
Plaintext
22 lines
451 B
Plaintext
//Shifting data to the left
|
|
|
|
int[] y;
|
|
|
|
void setup() {
|
|
size(800, 600);
|
|
y = new int[width];
|
|
}
|
|
|
|
void draw() {
|
|
background(204);
|
|
// Read the array from the beginning to the end
|
|
// i.e. shifting values to the left
|
|
for (int i = 0; i < y.length - 1; i++)
|
|
y[i] = y[i+1];
|
|
// Add new values to the end
|
|
y[y.length-1] = mouseY;
|
|
// Display each pair of values as a line
|
|
for (int i = 1; i < y.length; i++)
|
|
line(i, y[i], i - 1, y[i-1]);
|
|
}
|