chunkyorkshireman
YaBB Newbies
Offline
Posts: 40
checking elements of an array
Feb 5th , 2010, 12:06pm
Hi, importing .txt file data and want to draw nodes representing each imput. I started using the code in Processing handbook (loading characters, p431) so i understand that as not all entries are same length i need to pretend by 'tabbing' so processing reads the file. Some lines have more entries, so i just tabbed and typed a "." to even lengths. The code below works and represents each entry with a node but i don't want to represent the "." entries. How can i do this please? Code is: Record[] records; int recordCount; void setup() { size(300,300); noStroke(); fill(250); background(0); smooth(); String[]lines = loadStrings("familyMap.txt"); records = new Record[lines.length]; for (int i = 0; i < lines.length; i++) { String[] pieces = split(lines[i], '\t'); // Load data into array if (pieces.length > 1) { records[recordCount] = new Record(pieces); recordCount++; } } for (int i = 0; i < recordCount; i++) { // draw node at random location to represent parent float x = random(5, width-5); float y = random(5, height-5); ellipse(x,y,20,20); // Print to console: check println(i+1 + ": " + records[i].parent + " - " + records[i].child1 + " - " + records[i].child2 + " - " + records[i].child3 + " - " + records[i].child4 + " - " + records[i].child5); for (int j = 0; j < lines.length; j++) { // draw node at random location to represent children float x1 = random(5, width-5); float y1 = random(5, height-5); ellipse(x1,y1,8,8); } } }