newbie-question: understandig-problems with arrays
in
Programming Questions
•
7 months ago
hi,
I need your help again, I don't get the behaviour of arrays here.
For my understanding this code effects:
xpos[0] = 1
xpos[1] = 2
xpos[2] = 3
xpos[3] = 4
[…]
xpos[29] = mouseX;
I cant comprehend why all my bubbles are following my mouse?
For me xpos[0-28] are static values and just the last value (29) is able
to follow my mouse.
Please help me, i struggle with this for hours. -,-
—
I'm also very thankful for correcting my english sentences, it's very appreciated!
I need your help again, I don't get the behaviour of arrays here.
- int[] xpos = new int[70];
int[] ypos = new int[70];
void setup(){
size(500, 200);
smooth();
noStroke();
}
void draw(){
background (255);
for (int i=0; i< xpos.length - 1; i++) {
xpos[i] = xpos[i + 1];
ypos[i] = ypos[i + 1];
}
xpos[xpos.length - 1] = mouseX;
ypos[xpos.length - 1] = mouseY;
for (int i=0; i < xpos.length; i++) {
fill (0, 0, 0, 25);
ellipse (xpos[i], ypos[i], i / 0.75, i / 0.75);
}
}
- for (int i=0; i< xpos.length - 1; i = i + 1) {
xpos[i] = xpos[i + 1];
ypos[i] = ypos[i + 1];
}
xpos[xpos.length - 1] = mouseX;
ypos[xpos.length - 1] = mouseY;
For my understanding this code effects:
xpos[0] = 1
xpos[1] = 2
xpos[2] = 3
xpos[3] = 4
[…]
xpos[29] = mouseX;
I cant comprehend why all my bubbles are following my mouse?
For me xpos[0-28] are static values and just the last value (29) is able
to follow my mouse.
Please help me, i struggle with this for hours. -,-
—
I'm also very thankful for correcting my english sentences, it's very appreciated!
1