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
   Programs
(Moderators: fry, REAS)
   multidimensional arrays
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: multidimensional arrays  (Read 456 times)
jbk303


multidimensional arrays
« on: Apr 2nd, 2003, 1:15pm »

I am writing a program that will apply the Karplus-Strong plucked string algorithm to an array of colors. I decided to implement this using a 100 by 3 array. The compiler throws a NullPointerException. I have tried just about everything I can think of except 3 one dimensional arrays, which would be slower.
Does anyone have any ideas?
 
<CODE>
 
float[][] carray= new float[100][3];
int b=2;
int c=1;
color k = color(0,0,0);
int qw=0;
 
void setup() {
  carray = new float[100][3];
  size(100,200);
  for(int i=0; i<100; i++) {
    for(int ii=0; i<3; i++){
 carray[i][ii]=random(0,255);
    }
  }
}
 
void loop() {
  qw++;
  b+=c;
  c=-1*c;
  //println(b);
  for(int i=0; i<100; i+=b){
    for(int ii=0; ii<3; ii++){
 carray[i][ii]=(carray[i][ii]+carray[i+1][ii])/2;
 carray[i+1][ii]=(carray[i][ii]+carray[i+1][ii])/2;
    }
  }
  for(int i=0; i<100; i++){
    k = color(carray[i][1], carray[i][2], carray[i][3]);
    point(i, qw);
  }
}
 
</CODE>
 
benelek

35160983516098 WWW Email
Re: multidimensional arrays
« Reply #1 on: Apr 2nd, 2003, 2:31pm »

as far as i can see, u have two problems:
 
1. ur defining a variable of type "color" before the setup() section. this will work:
Code:
void setup() {
  size(100,100);
  k = color(0,0,0);
}
color k;
void loop() {
}

but this will not:
Code:
void setup() {
  size(100,100);
}
color k = color(0,0,0);
void loop() {
}

 
 
2. ur getting an outOfBounds exception a few times because ur trying to access carray[bla][3], where only carray[bla][0 to 2] exists. for instance:
Code:

k = color(carray[i][1], carray[i][2], carray[i][3]);

and a similar problem with accessing i=99 and i+1=100 in...
Code:

carray[i+1][ii]=(carray[i][ii]+carray[i+1][ii])/2;  

 
 
but i've never heard of the Karplus-Strong plucked string algorithm. mind explaining the idea?
 
 
-jacob
 
jbk303


Re: multidimensional arrays
« Reply #2 on: Apr 3rd, 2003, 1:48am »

Thanks, that cleared up those errors. The karplus-strong algorithm takes a wavetable filled with a noisy sound sample and reads it, averages the current and previous samples, and feeds the average back into the wavetable. This is done until the wavetable contains a uniform value. In other words: it repeatedly lowpasses the sample. I thought it might be cool to visualize. Once I have this working it will need some tweaks to look better. Thanks for your help,
Josh
 
Pages: 1 

« Previous topic | Next topic »