Screen not refreshing

edited April 2016 in Questions about Code

I am trying to load variables from a table into text on Processing but at the moment the code just seems to write the variables on top of themselves. I would like these variables to change per second (hence the delay at the end of void draw()). The results (text) also seem to take a very long time to show up on the screen. I have tried various ways but I do not know what it is that I'm doing wrong. This is the code:

Table table; TableRow row; int fData;

void setup() { size(800, 500); background(255); table = loadTable("test2.csv", "header");

println(table.getColumnCount() + " columns in table"); println(table.getRowCount() + " rows in table"); println("Date: " + table.getString(1, 0)); println("Start time: " + table.getString(0, 1)); println("Duration: " + (table.getRowCount()/60) + " minutes");

}

void draw () { background(255,255,255); text("Date: "+table.getString(0,0), 30,400); fill(0,0,0);

for (int i = 0; i < 23; i = i+1) {

fData=((table.getInt(i,2))/1000); text("Time: "+table.getString(i,1), 30, 420); text("Frequency: "+table.getInt(i,2), 30, 440); text(("Frequency to alpha: "+fData), 30, 460);

delay(1000);
}

}

Answers

  • Sounds like the program gets stuck in some infinite loop.

    Can you make your code readable? Hit ctrl+t in Processing before exporting, then hightlight your code here and click the C button (ctrl+o).

    https://forum.processing.org/two/discussion/32/how-to-format-text-and-code-on-the-new-forum/p1

  • Table table;
    TableRow row;
    int fData;
    String [] frequency;
    String [] time;
    int index = 0;
    
    void setup() {
      size(800, 500);
      background(255);
      //font = createFont("Arial",10,true);
      table = loadTable("test2.csv", "header");
      time = table.getStringColumn(1);
      frequency = table.getStringColumn(2);
    
      println(table.getColumnCount() + " columns in table"); 
      println(table.getRowCount() + " rows in table"); 
      println("Date: " + table.getString(1, 0)); 
      println("Start time: " + table.getString(0, 1));
      println("Duration: " + (table.getRowCount()/60) + " minutes"); 
      //  println(time);//show me all time
      //println(frequency);//show me all frequencies
    
    
      //text(fData, 30,30);// show me fData
      //println(split(data, ";"));
      // noStroke();
    
      //test 1 (if I remove this then the main rectangle turns white)
      //rect(0, 0,1,1);
      //fill(0,0,0);
    
      //fData test
      // noStroke();
      //fill(0, fData);//rectangle
      //rect(25, 25, 750, 450);
    
      // fill(0);//text color
      //text(("Alpha value: " + fData), 10,20);
      //fill (255,255,255);
    }
    
    void draw () {
      background(255); 
      text("Date: "+table.getString(0, 0), 30, 340);
      text("Start time: "+ time[index], 30, 360);
      fill(0); 
    
    
      for (int i = 0; i < 1575; i = i+1) {
        fData=((table.getInt(i, 2))/1000);// alpha range 0-255
        println(fData);
    
        fill(0);
        text("End time: " + time[i], 30, 380);
        text("Times:["+table.getString(i, 1)+"]", 30, 420); 
        // println(" Frequency: "+table.getInt(i,2));
        //  text("Frequency: "+table.getInt(i,2), 30, 440); 
        fill(255);
        rect(0, height-100, width, 100);
        fill(0);
    
    
    
        text("fData:["+fData+"]", 30, 440);
        // text(("Frequency to alpha: ["+fData+"]"), 30, 460);
        //println(fData);
        //rect(25, 25, 750, 450);
        float number = +table.getInt(i, 2);
        println(number);
    
        text("#["+number+"]", 30, 480);
      }
    
      //delay(1000);  
      //  loop();
    }
    
Sign In or Register to comment.