My routines to read and extract the data from the text files works within void setup(), but when I try to use that data in a void draw() section, the program "hangs", sits there after printing the number of lines in the file and that's it. I've adjusted variables' scope, compared my code to many examples posted here, put in hard-coded line draws to test for simple drawing, but no change. Any suggestions as to what might be the issue are much appreciated.
- import processing.opengl.*;
- float x0 = 0;
- float y0 = 0;
- float z0 = 0;
- float x1 = 0;
- float x2;
- float y1 = 0;
- float y2;
- float z1 = 0;
- float z2;
- String[] lines;
- void setup(){
- size(500,400, OPENGL); // 500 x 400 px window
- stroke(255);
- lines = loadStrings("test.txt"); // load test file
- print("There are " + lines.length + " lines in the file");
- }
- void Draw() {
- for ( int i=0; i<lines.length; i++){ //cycle through the file line at a time
- println("line "+i); // print line number
- String[] list = trim(split(lines[i], ' ')); //split the line into space=delimited snippets
- for (int n=0; n<list.length; n++) { //cycle through the snippets per line
- if(list[n].indexOf("X")!=-1) { // extract x value
- String xval = list[n];
- int xlen = xval.length();
- String xnum = xval.substring(1, xlen);
- x2 = float(xnum);
- println("X value = " + x2); // print found X value to console
- } else {
- if (list[n].indexOf("Y")!=-1) { // extract y value
- String yval = list[n];
- int ylen = yval.length();
- String ynum = yval.substring(1, ylen);
- y2 = float(ynum);
- println("Y value = " + y2); // print found Y value
- }else {
- if (list[n].indexOf("Z")!=-1) { // extract Z value
- String zval = list[n];
- int zlen = zval.length();
- String znum =zval.substring(1, zlen);
- z2 = float(znum);
- println("Z value = " + z2); // print found Z value
- }
- }
- }
- }
- line(x1, y1, z1, x2, y2, z2); // plot x,y,z data as next line segment
- x1 = x2; //transfer values for start point of next line segment
- y1 = y2;
- z1 = z2;
- }
- }
1