PVector in if() loop -> path should stay open; first and last point should not be connected.
in
Programming Questions
•
3 years ago
Hi!
I'm working with a PVector in a if() loop.
I want to draw a line through certain points.
The problem is that the if() loop also connects the first and last point so the path becomes closed.
That is not what I want, it has to stay a line instead of a rectangle or something.
This is the code:
- import processing.opengl.*;
- import peasy.*;
- ArrayList points = new ArrayList();
- PeasyCam cam;
- void setup() {
- size(1200,800,OPENGL);
- cam = new PeasyCam(this, 2000);
- cam.setMinimumDistance(500);
- cam.setMaximumDistance(1000000);
- background(0);
- smooth();
- frameRate(15);
- }
- void draw() {
- background(0,0,0,75);
- lights();
- translate(-width*2, -height/2);
- lights();
- a_line();
- }
- void a_line() {
- String[] a_line = loadStrings("a_line.txt");
- for(int i = 0; i < a_line.length; i++) {
- String s = a_line[i];
- int pos = s.indexOf('°');
- String a_linex = s.substring(0,pos);
- s = s.substring(pos+1);
- pos = s.indexOf('-');
- String niets = s.substring(0,pos);
- s = s.substring(pos+1);
- pos = s.lastIndexOf('°');
- String a_liney = s.substring(0,pos);
- float x = float(a_linex.trim());
- float y = float(a_liney.trim());
- float xf = ((x-40)*10000)-5000;
- float yf = ((y-73)*10000)-9000;
- strokeWeight(0.5);
- stroke(255);
- PVector V = new PVector(xf,yf);
- points.add(V);
- if(points.size() > 1) {
- PVector V1 = (PVector) points.get(points.size() -1);
- PVector V2 = (PVector) points.get(points.size() -2);
- line(V1.x, V1.y, V2.x, V2.y);
- }
- }
- }
The txt file with the coordinates looks like this:
- 40.632788°N - 73.947612°W - Brooklyn College / Flatbush Avenue
- 40.639912°N - 73.94846°W - Newkirk Avenue
- 40.645122°N - 73.94906°W - Beverly Road
- 40.650755°N - 73.950005°W - Church Avenue
- 40.657039°N - 73.950262°W - Winthrop Street
- 40.663061°N - 73.950863°W - Sterling Street
- 40.668009°N - 73.950691°W - President Street
- 40.670711°N - 73.958545°W - Franklin Avenue / Botanic Garden
- 40.671622°N - 73.96275°W - Eastern Parkway / Brooklyn Museum
- 40.674584°N - 73.970518°W - Grand Army Plaza
- 40.680833°N - 73.97511°W - Bergen Street
- 40.684462°N - 73.978758°W - Atlantic Avenue
- 40.688709°N - 73.980904°W - Nevins Street
- 40.690531°N - 73.985109°W - Hoyt Street / Fulton Mall
- 40.693655°N - 73.990216°W - Court Street / Borough Hall
- 40.697397°N - 73.993049°W - Clark Street
- 40.706311°N - 74.009528°W - Wall Street
- 40.709515°N - 74.006374°W - Fulton Street/Broadway / Nassau Street
- 40.712655°N - 74.009657°W - Chambers Street / World Trade Centre / Park Place
- 40.719°N - 74.007°W - Franklin Street
- 40.722°N - 74.006°W - Canal Street
- 40.728592°N - 74.005322°W - Houston Street
- 40.733°N - 74.003°W - Christopher Street / Sheridan Square
- 40.738°N - 73.999°W - 14th Street
- 40.741°N - 73.998°W - 18th Street
- 40.744°N - 73.996°W - 23rd Street
- 40.747°N - 73.993°W - 28th Street
- 40.751°N - 73.991°W - 34th Street / Penn Station
- 40.756°N - 73.987°W - Times Square / 42nd Street
- 40.761°N - 73.984°W - 50th Street
- 40.767997°N - 73.981934°W - 59th Street / Columbus Circle
- 40.774°N - 73.982°W - 66th Street / Lincoln Center
- 40.779°N - 73.982°W - 72nd Street
- 40.784°N - 73.980°W - 79th Street
- 40.788°N - 73.976°W - 86th Street
- 40.794°N - 73.972°W - 96th Street
- 40.798°N - 73.953°W - Central Park North / 110th Street
- 40.802°N - 73.950°W - 116th Street
- 40.807°N - 73.945°W - 125th Street
- 40.814°N - 73.941°W - 135th Street
- 40.818°N - 73.927°W - 149th Street / Grand Concourse
- 40.815807°N - 73.91726°W - 3rd Avenue / 149th Street
- 40.816°N - 73.908°W - Jackson Avenue
- 40.819°N - 73.901°W - Prospect Avenue
- 40.822°N - 73.897°W - Intervale Avenue
- 40.824°N - 73.893°W - Simpson Street
- 40.830°N - 73.892°W - Freeman Street
- 40.837°N - 73.888°W - 174th Street
- 40.840°N - 73.880°W - West Farms Square / East Tremont Avenue
- 40.841°N - 73.874°W - East 180th Street
- 40.849°N - 73.868°W - Bronx Park East
- 40.857°N - 73.868°W - Pelham Parkway
- 40.865°N - 73.867°W - Allerton Avenue
- 40.871°N - 73.867°W - Burke Avenue
- 40.877°N - 73.866°W - Gun Hill Road
- 40.883°N - 73.863°W - 219th Street
- 40.888°N - 73.860°W - 225th Street
- 40.893°N - 73.857°W - 233rd Street
- 40.898°N - 73.854°W - Nereid Avenue
- 40.903°N - 73.850°W - Wakefield / 241st Street
Can anybody help me out with the paths?
And also another small problem: I use peasycam and it gets really really slow.
Why is this? And does anybody have an idea how to fix that?
Great thanks in advance!!
1