Reading text files

edited January 2017 in Questions about Code

So I have a text file with 2 numbers on every line, which is the x coordinate and y coordinate of a point. I have trouble reading the text file and using all the coordinates to draw my shape. help plz!!!

Here is how the text file looks like:
320.859 283.133
313.715 287.457
310.332 295.332
302.996 300.285
296.805 307.137
292.359 297.824
286.586 304.398
.........(with 700 more lines)

And my code:

void setup() {
  size(400, 400);
  background(0);
  stroke(255);
  strokeJoin(ROUND);
  strokeWeight(2);
  String[] dots = loadStrings("design.txt");

  beginShape();
  for (int i = 0; i < dots.length; i+= 1) {
    vertex(float(dots[i]), float(dots[i]));
  }
  endShape(CLOSE);
}

Answers

Sign In or Register to comment.