Coordinates out of bounds! ERROR ... with pics on grow
in
Programming Questions
•
6 months ago
Hey people!
I'm trying to draw pictures in a canvas. The pics should grow according to the position of the mouse. When i do this I'm getting an "ArrayIndexOutOfBoundsException: Coordinate out of bounds!" in line 51. If i draw a rectangle instead of a picture it works just fine. I'm new to Processing and i think there is something wrong with my class.
Looking forward to some answers and wish u happy coding!
THX,
Anorak
I'm trying to draw pictures in a canvas. The pics should grow according to the position of the mouse. When i do this I'm getting an "ArrayIndexOutOfBoundsException: Coordinate out of bounds!" in line 51. If i draw a rectangle instead of a picture it works just fine. I'm new to Processing and i think there is something wrong with my class.
Looking forward to some answers and wish u happy coding!
THX,
Anorak
- int a = 3,index,z, Xstart, Ystart;
- Pictures[] myArray;
- void setup( ) {
- size(400, 400);
- myArray = new Pictures[a];
- PImage img = loadImage("lordhelmchen.jpg");
- for (int i = 0; i < 3; i++) {
- myArray[index++] = new Pictures(img);
- }
- }
- void draw( ) {
- background( 0 );
- if(mousePressed == true) {
- myArray[z].update(Xstart, Ystart);
- myArray[z].draw(Xstart, Ystart);
- }
- }
- void mousePressed( ) {
- Xstart = mouseX;
- Ystart = mouseY;
- }
- void mouseReleased( ) {
- z++;
- }
- class Pictures {
- PImage img;
- int Xstart, Ystart, Xend, Yend, Xb, Yb;
- Pictures(PImage pic) {
- img = pic;
- }
- void update(int Xstart, int Ystart) {
- Xend = mouseX;
- Yend = mouseY;
- println("Start " + Xstart + "," + Ystart);
- println("End " + Xend + "," + Yend);
- }
- void draw(int Xstart, int Ystart) {
- Xb = (Xstart < Xend)? Xstart : Xend;
- Yb = (Ystart < Yend)? Ystart : Yend;
- img.resize(abs(Xend - Xstart), abs(Yend - Ystart));
- println("BBB " + Xb + "," + Yb);
- if (Xstart != Xend && Ystart != Yend) {
- image(img, Xb, Yb);
- }
- //rect(Xstart, Ystart, Xend-Xstart, Yend-Ystart);
- }
- }
1