controlling line drawing from a text file
in
Programming Questions
•
7 months ago
Hello all
I want to draw lines based on coordinates from a text file formatted like so:
[0] x1,y1
[1] x2,y2
[2] x3,y3
..etc..
..which I have managed to get into 2 PVector classes, via tips on
iainmaxwell's Supermanoeuvre blog.
I'd like to draw one line after the other when the user hits the RIGHT key.
At the moment, the program draws the first line, then all of the others together after RIGHT is hit only once.
Where am I going wrong?
I am sure there is a better way to draw the line from the data as well.
best
P
- int grey = 180;
- int x = 0;
- ArrayList pointList = new ArrayList();
- void setup(){
- size(400,400);
- background(255);
- stroke(grey,grey,grey);
- importTextFile();
- }
- void draw(){
- PVector v1 = (PVector) pointList.get(x);
- PVector v2 = (PVector) pointList.get(x+1);
- line(v1.x,v1.y,v2.x,v2.y);
- if(keyCode == RIGHT){
- x = x + 2;
- }
- }
- void importTextFile(){
- String[] strLines = loadStrings("points.txt");
- for(int i = 0; i < strLines.length; ++i){
- String[] arrTokens = split(strLines[i], ',');
- float xx = float(arrTokens[0]);
- float yy = float(arrTokens[1]);
- pointList.add(new PVector(xx,yy));
- }
- }
1