We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
array of array (Read 863 times)
array of array
Nov 6th, 2007, 2:50am
 
just a quick question...how do i write an array of an array?....

particle [][] newdrop;
Particle [] expo;
int enum = 5;
int nnum = 5;

expo =  new Particle[enum];

// i deploy my array expo...then i want my second array newdrop to be deployed around all the expo particle...

newdrop =  new Particle[enum][nnum];

//so i wrote

for (int e = 0; e < enum; e++){
   for (int n = 0; n< nnum; n++){
     
newdrop[e][n] = physics.makeParticle( 1.0, random((expo[e].position().x()+30),(expo[e].position().x()-30)) , random((expo[e].position().y()+30),(expo[e].position().y()-30)), 0 );

   }
}

//this does create an nnum of particles..
//but what i get is a nnum of particles one on top of the other...and not randomly placed around each expo[] particle....but just around one....

i think the porb is that i don t know how to write an array of array.......but dunno..any help??

thx


Re: array of array
Reply #1 - Nov 6th, 2007, 5:25pm
 
ha, i think you have your random numbers the wrong way around. for instance, if expo[e].position().x() was 0 it would evaluate to

random(+30, -30);

which might confuse it (because the high value is lower than the low value)

as a test i just wrote

for (int i = 0 ; i < 20 ; i++) {
 println(random(10, -10));
}

and got 20 lots of 10.0
Re: array of array
Reply #2 - Nov 6th, 2007, 6:20pm
 
thx for the reply....but i m not sure i understood what u mean...u r suggesting i write the range x+30 and x-30 differently?....

Re: array of array
Reply #3 - Nov 6th, 2007, 7:00pm
 
random function should work like this

random( minValue, maxValue );

you have your max value in the min parameter.. that should be your problem.

thats what last post was talking about
Re: array of array
Reply #4 - Nov 7th, 2007, 1:38am
 
ok...txh....i understood that...i llt ry it now...thx...any suggestion about how to write an array of an array??

thx a lot
Re: array of array
Reply #5 - Nov 7th, 2007, 7:23am
 
Code:
int[][] a = new int[2][2];
a[0][0] = 0;
a[0][1] = 1;
a[1][0] = 2;
a[1][1] = 3;

for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
println(a[i][j]);
}
}
Re: array of array
Reply #6 - Nov 7th, 2007, 10:45am
 
your 2d arrays weren't the problem, they were fine, you just had the min and max in your random() the wrong way around causing them to all take the same value.

(maybe random() should handle descending ranges).
Re: array of array
Reply #7 - Nov 9th, 2007, 6:11pm
 
thx to all..actually it worked...i ll post some resoults in some days....thx
Page Index Toggle Pages: 1