Currently in progress is an attempt to create a sketch where spinning squares appear on click command (where the cursor is) and follow in relation (not directly to) the mouse. I'm very stuck. I'm using arrays to set up the squares, and a mousePressed function to create the squares where the mouse is clicked but it's not working. The program keeps giving me the 'array out of bounds' error and I have tried numerous times to fix it but to not avail. Nothing I have googled or looked up in my book is helping.
int numRect = 0;
float x = 100;
float y = 100;
int indexPosition = 0;
float[] rectXps = new float[0];
float[] rectYps = new float[0];
void setup() {
size(700, 400);
background(255);
smooth();
}
void draw() {
rectXps[indexPosition] = mouseX;
rectYps[indexPosition] = mouseY;
int i = 0;
while (i > 0) {
rectXps[i] = mouseX/2;
rectYps[i] = mouseY/2;
i = i+1;
}
int j = 0;
rect(rectXps[j], rectYps[j], random(x), random(y));
}
void mousePressed() {
numRect = numRect + 1;
rectXps = expand(rectXps, numRect);
rectYps = expand(rectYps, numRect);
}
No comments:
Post a Comment