Files
sunny9898/task8/wk9/wk9_example_3b/wk9_example_3b.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

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]);
}