I don't know why it's not rendering

edited March 2016 in Questions about Code

Hi! So I've been playing around with importing files. I can't figure out why the rectangle in the draw isn't rendering.

For context, "filenames.txt" contains a long list of the names of the files I'm importing. These files are loaded and turned into arrays, then these arrays are separated into individual words which are then passed through the "emotions.csv".

I know that it has been properly importing the different files—I've tested by printing the filenames[r] and by printing the words that it's looking up in the "emotions.csv". I just can't figure out why it's not showing anything that I'm drawing, even when I put the rectangle at the start of the draw.

Table table;

void setup() {
  size (100, 100);
  background (255);
  smooth ();
  table = loadTable("emotions.csv", "header");
  fill(0);
}

void draw(){
  fill(0);
  rect(0, 0, 10,10);

  String[] filenames = loadStrings ("filenames.txt");

  for (int r = 0; r < filenames.length; r++) {
    String[] lines = loadStrings(filenames[r]);

    for (int i = 0; i < lines.length; i++) {
      lines[i] = lines[i].toLowerCase();

      String[] list = splitTokens(lines[i], " &,+.:#<>[]1234567890~*()-@/_-%^$!{}|;'/");

      for (int x = 0; x < list.length; x++) {
        TableRow result = table.findRow(list[x], "Word");
          if (result == null) {
          }
          else {
            println(result.getInt("V.Mean.Sum"));
          }
        }
      } 
    }
  }  

Answers

  • In a first glance I see that in line 15 you will load the text file as fast as your FPS (e.g. 60 times per second) so you can put this line inside setup function and make String[] filenames a global variable (put it after the Table table).

  • Thanks! It still doesn't seem to render the rectangle, though, but all the data still loads fine.

  • edited March 2016

    Here is some template code to help you, I don't know the data format you want to load, but if you say that it works you probably are OK.

    Table table;
    
        void setup()
        {
            // size should be large enough to see some graphics 
            size(500, 500);
            rectMode(CENTER);
    
            // load data here
            loadSomeData();
        }
    
        void draw() {
    
            // this will clear the screen
            background(200);
    
            // this will draw a simple rectangle
            fill(200, 0, 0);
            rect(mouseX, mouseY, 100, 100);
        } 
    
    
        void loadSomeData()
        {
            //table = loadTable("emotions.csv", "header");
            //String[] filenames = loadStrings ("filenames.txt");
            //for (int r = 0; r < filenames.length; r++) {
            //    String[] lines = loadStrings(filenames[r]);
            //    for (int i = 0; i < lines.length; i++) {
            //        lines[i] = lines[i].toLowerCase();
            //        String[] list = splitTokens(lines[i], " &,+.:#<>[]1234567890~*()-@/_-%^$!{}|;'/");
            //        for (int x = 0; x < list.length; x++) {
            //            TableRow result = table.findRow(list[x], "Word");
            //            if (result == null) {
            //            } else {
            //                println(result.getInt("V.Mean.Sum"));
            //            }
            //        }
            //    }
            //}
        }
    
Sign In or Register to comment.