FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   ArrayIndexOutOfBoundsException , or, screen wrap
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: ArrayIndexOutOfBoundsException , or, screen wrap  (Read 485 times)
gkoshra

WWW Email
ArrayIndexOutOfBoundsException , or, screen wrap
« on: Mar 21st, 2003, 2:52pm »

Hello,
I've made a wee program that just draws a wandering pixel on the screen. I started with no constraints as to where it could go, and it walked off the side of my program, only to appear on the other side. I thought great! wrap around and I didn't even have to do anything. Then it walked off the bottom of my screen and I got the out of bounds exception. It does the same when it goes off the top.
 
I didn't really know where to post this, is it a bug? Or is there something i'm missing in the setup bit? Anyway, what I wanted to know was whether the first pixel at the top left hand of the screen had the coordinates 0,0.
 
Cheers.
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: ArrayIndexOutOfBoundsException , or, screen wr
« Reply #1 on: Mar 21st, 2003, 5:07pm »

yup. non-translated, default top left is 0,0.
would be nice if u could post your code if u want...
 
skloopy

WWW
Re: ArrayIndexOutOfBoundsException , or, screen wr
« Reply #2 on: Mar 23rd, 2003, 6:43am »

Are you using the pixels[] array for drawing your pixel? it's probably because the pixels array is one dimensional. So when you have a 10 x 10 image pixel 9 is on the right border, but pixel 10 is on the next line, like a paragraph. but there are no pixels below 0 or above 99.
 
Does that help?
 
gkoshra

WWW Email
Re: ArrayIndexOutOfBoundsException , or, screen wr
« Reply #3 on: Mar 25th, 2003, 10:00am »

Gah! Yes I see now, so if I kept on drawing pixels with an x position that got incremented constantly and a y postition that never changed, then the line would go off the side of the screen and start again on the other side, but one row below the last. I should have know really.
 
The problem cropped up as I was making this program...
 
http://proce55ing.net/discourse/yabb/board_Contribution_Automat_ed_action_display_num_1046083703.html
 
There are constraints in this to stop it going off the screen, but if you want to see it break, just take the bits out that are like this...
 
    if(ant2x>390 || ant2y>390 || ant2x<10 || ant2y<10){
 ant2x=200;
 ant2y=200;
    }
 
I'm sure I didn't need to tell you that though.
 
Thanks for the help guys.
 
Ben.
 
 
Pages: 1 

« Previous topic | Next topic »