(Probably) Very simple array question
in
Programming Questions
•
2 years ago
Hi,
I want to create an array that each frame is fed the X position of the mouse, so that I can recall later on the position at a certain frame in the past. I've written the following little piece of code to test this idea, which builds an array and then prints the resulting array when it finishes a loop of 99 frames. However, when it prints the array at the end, only the final frame has a value, all the others are" 0.0".
I'm very confused, and new not only to Processing, but programming as a whole.
Any help much appreciated!
I want to create an array that each frame is fed the X position of the mouse, so that I can recall later on the position at a certain frame in the past. I've written the following little piece of code to test this idea, which builds an array and then prints the resulting array when it finishes a loop of 99 frames. However, when it prints the array at the end, only the final frame has a value, all the others are" 0.0".
I'm very confused, and new not only to Processing, but programming as a whole.
Any help much appreciated!
void setup() {
size(200, 200);
noLoop();
}
void draw() {
float[] mousearray = new float[100];
int frame = frameCount;
mousearray[frame] = mouseX;
println(mousearray[frame]);
if(frameCount < 99) {
loop();
} else {
noLoop();
}
if(frameCount == 99) {
println(mousearray);
}
}
1