Need help with array

Hello I would like to get this code work. The problem is that I can't set a specific index to the array "log" because its a log so the number of value in it will always change. Excuse my english. Thanks

PGraphics pg;
int[] box={1,5,6,10,11,50};
int[][][] log;

void setup(){
  size(int(displayWidth/1.5),int(displayHeight/1.5));
  frameRate(5);

  pg=createGraphics(width,height);

  pg.beginDraw();
  pg.colorMode(RGB,height,255,width);
  for(int y=0; y<height; y++){
    for(int x=0; x<width; x++){
      pg.stroke(y,240,x);
      pg.point(x,y);
    }
  }
  pg.colorMode(RGB,255);
  pg.noStroke();
  pg.rectMode(CORNERS);
  pg.fill(255,150);
  for(int i=0; i<box.length/2; i++){
    pg.rect(width/50,height/50*box[i*2],width-width/50,height/50*box[i*2+1]);
  }
  pg.fill(0);
  pg.textAlign(CENTER,CENTER);
  pg.textSize(height/50*((box[0]+box[1])/2));
  pg.text("TempLog",width/2,height/50*((box[0]+box[1])/2));
  pg.endDraw();

  update();
}

void draw(){
  clear();
  image(pg,0,0);
}

void update(){
  for(int a=0;a<loadStrings("E:/TEMPLOG/LOG.TXT").length;a++){
    for(int b=0;b<split(loadStrings("E:/TEMPLOG/LOG.TXT")[a],"|").length;b++){
      log[a][b]=int(split(split(loadStrings("E:/TEMPLOG/LOG.TXT")[a],"|")[b],":"));
    }
  }
  println(log);
}

LOG.TXT:

15|1:22.3|2:24|3:23.9|4:20|5:18|
15|1:18|2:20|3:23.9|4:24|5:22.3|6:22|
20|1:0|2:2|3:4|4:6|5:8|
15|

Answers

  • Answer ✓

    Hey, I'm not sure what you are trying to do, but one problem is that you're loading the textfile many many times in the update function. better read it only once and work with copies of the read. Also maybe you should maybe rethink using a 3dimensional array. sometimes its usefull,in math but maybe it would make more sense to create a class, maybe a plane, for each line in the file and give that an 2d array, or an array of another class.. just suggestions. sorry no time to code atm :)

  • Answer ✓

    If you could explain what the numbers in the log.txt file mean we could offer better advice. Also some of the numbers are floats e.g. 23.9 so will not go in an int array.

  • Thanks you guys I'll work on it

  • TEST

    It look like that for the moment I'll add other thing like the max temp min temp average temp and the possibility to choose only one graph line :)

Sign In or Register to comment.