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

26 lines
534 B
Plaintext

//Example from Processing Handbook 2nd Edition
//P.421 Chapter 28 Example 15
//Shifting data to the right
int[] y;
void setup() {
size(800, 600);
y = new int[width];
}
void draw() {
background(204);
// Read the array from the end to the
// beginning to avoid overwriting the data
for (int i = y.length-1; i > 0; i--) {
y[i] = y[i-1];
}
// Add new values to the beginning
y[0] = 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]);
}
}