We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, Any hint how this piece of code make better? Thanks to iainmaxwell tutorial I made simple diagram, but for every color I'm using extra loop and void. Can anybody give me any hint how to read r/g/b from csv and add to single loop?
ArrayList pointListedu1; // arraylist to store the points in
ArrayList pointListedu2;
void setup() {
size(1000, 500, OPENGL);
background(255);
pointListedu1 = new ArrayList(); // instantiate an ArrayList
importTextFileedu1(); // call our custom function
pointListedu2 = new ArrayList();
importTextFileedu2();
void draw() {
//-------------------------------- GENERAL
background(0,0,50);
lights();
stroke(110);
//-------------------------------- VISUALIZE THE POINT SET
stroke(255, 215, 0); // gold
for (int i = 0; i < pointListedu1.size (); ++i) {
PVector V = (PVector) pointListedu1.get(i);
ellipse(V.x, V.y, 0.1, 0.1);
}
stroke(255, 165, 0); // orange
for (int i = 0; i < pointListedu2.size (); ++i) {
PVector V = (PVector) pointListedu2.get(i);
ellipse(V.x, V.y, 0.1, 0.1);
}
void importTextFileedu1() {
String[] strLines = loadStrings("edu1.txt"); // the name and extension of the file to import!
for (int i = 0; i < strLines.length; ++i) {
String[] arrTokens = split(strLines[i], ','); // use the split array with character to isolate each component
float xx = float(arrTokens[0]); // cast string value to a float values!
float yy = float(arrTokens[1]); // cast string value to a float values!
float zz = float(arrTokens[2]);
pointListedu1.add( new PVector(xx, yy, zz) ); // add values to a new array slot
}
}
void importTextFileedu2() {
String[] strLines = loadStrings("edu2.txt"); // the name and extension of the file to import!
for (int i = 0; i < strLines.length; ++i) {
String[] arrTokens = split(strLines[i], ','); // use the split array with character to isolate each component
float xx = float(arrTokens[0]); // cast string value to a float values!
float yy = float(arrTokens[1]); // cast string value to a float values!
float zz = float(arrTokens[2]);
pointListedu2.add( new PVector(xx, yy, zz) ); // add values to a new array slot
}
}
Comments
By chance you meant a general loadCoordsFile() method which returns a List<PVector>? 8-|