PVector array filled with static data

Hi team,

I have an issue regarding the correct way to assign PVector data in an array.
the data is derived from earlier task (see image and code below), i only want to us the output as a PVector in an array (static coded).

picture used in datafolder:

resulting array that is desired to be used in other sketch:
[ 30.0, 50.0, 136.0 ] [ 39.0, 60.0, 149.0 ] [ 47.0, 68.0, 159.0 ] [ 53.0, 76.0, 169.0 ] [ 58.0, 84.0, 177.0 ] [ 66.0, 95.0, 187.0 ] [ 87.0, 126.0, 195.0 ] [ 104.0, 151.0, 203.0 ] [ 118.0, 174.0, 211.0 ] [ 130.0, 192.0, 217.0 ] [ 142.0, 202.0, 213.0 ] [ 148.0, 206.0, 194.0 ] [ 154.0, 208.0, 172.0 ] [ 163.0, 209.0, 147.0 ] [ 169.0, 213.0, 115.0 ] [ 187.0, 220.0, 107.0 ] [ 207.0, 229.0, 102.0 ] [ 223.0, 238.0, 97.0 ] [ 239.0, 246.0, 91.0 ] [ 252.0, 250.0, 88.0 ] [ 253.0, 222.0, 82.0 ] [ 253.0, 190.0, 77.0 ] [ 254.0, 151.0, 72.0 ] [ 255.0, 100.0, 62.0 ] [ 251.0, 91.0, 59.0 ] [ 247.0, 82.0, 52.0 ] [ 243.0, 72.0, 46.0 ] [ 240.0, 59.0, 38.0 ] [ 213.0, 54.0, 35.0 ] [ 179.0, 47.0, 32.0 ] [ 141.0, 38.0, 31.0 ] [ 84.0, 28.0, 29.0 ]

i tried variations of PVector colorLegendWind [] = [ 30.0, 50.0, 136.0 ] [ 39.0, 60.0, 149.0 ] [ 47.0, 68.0, 159.0 ] [ 5…

knowing it is wrong, hope a hint can be given.

snippet:

float x1;
PImage img;
float editr;
PVector colorLegendWind [] = new PVector[32];
//PVector colorLegendWind []= new PVector {( 1,2,3) (1,2,3)}; 
//PVector colorLegendWind []= ( 1,2,3) (1,2,3); 


void setup(){
 size(1000,900); 
 
// colorLegendWind= [( 30.0, 50.0, 136.0 ) ( 39.0, 60.0, 149.0 )] ;
 
 
 
 img = loadImage("wind_32sc_0to6.JPG");
 x1= 162;
 y1= 865;
 y2= 110;
  editr= (y1-y2)/31;
  
}
  
  void draw(){
   background(255); 
    
    image(img,0,0);
    img.loadPixels();
    //println(mouseX,mouseY);
    
    for (int i=0;i<32; i++){
      
      stroke(255);
      strokeWeight(5);
      point(x1,y1-i*editr);
      color c = get(int(x1+5), int(y1-i*editr));
      //println(red(c),green(c),blue(c));
      colorLegendWind[i]= new PVector(red(c),green(c),blue(c));
      
    }
print( colorLegendWind);
noLoop();
}
1 Like

Hey,

Can you post your code in plain text by pressing Ctrl+T in the Processing IDE then use the </> button on the forum to insert it so people can use your code and understand it.

Thank you for pointing out,

If you want to create an array w/ its elements already initialized at the same time its variable is declared, we need to use curly braces {} in Java: :coffee:

PVector[] vecs = { new PVector(), new PVector(PI, TAU), PVector.random3D(this) };

If the variable already exists and you wanna assign an already filled array to it, you’re gonna need to use the operators new & [] as well: :nerd_face:

PVector[] vecs;
vecs = new PVector[] { new PVector(), new PVector(PI, TAU), PVector.random3D(this) };
2 Likes

Thank you for pointing out that that is the way forward. Was afraid detailed declaration is needed in order to make it work. But very happy knowing how to continue. Thank you. Mr GotoLoop