Skip to content

Instantly share code, notes, and snippets.

@seanmtracey
Created March 9, 2014 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmtracey/9449773 to your computer and use it in GitHub Desktop.
Save seanmtracey/9449773 to your computer and use it in GitHub Desktop.
JSONArray coordinates;
List<String> idx = new ArrayList<String>();
int iter = 0;
float shortest = 10000;
import java.util.*;
void setup() {
frameRate(30);
coordinates = loadJSONArray("coordinates.json");
print(coordinates.size());
for(int x = 0; x < 89; x++){
idx.add("" + x);
}
size(600, 600);
}
void draw() {
background(255, 255, 255);
int r = int(random(255));
int g = int(random(255));
int b = int(random(255));
stroke(r,g,b);
noFill();
beginShape();
float distance = 0;
for (int x = 0; x < coordinates.size() - 1; x++) {
JSONObject pointA = coordinates.getJSONObject(parseInt(idx.get(x)));
JSONObject pointB = coordinates.getJSONObject(parseInt(idx.get(x + 1)));
float xA = pointA.getFloat("latitude");
float yA = pointA.getFloat("longitude");
float xB = pointB.getFloat("latitude");
float yB = pointB.getFloat("longitude");
distance += Math.sqrt( ( xA - xB ) * ( xA - xB ) + ( yA- yB ) * ( yA - yB ) );
xA = map(xA, 50.7, 50.8, 100, 500);
yA = map(yA, -1.9, -1.7, 100, 500);
vertex(xA - 40, yA + 80);
ellipse(xA - 40, yA + 80, 10, 10);
}
endShape(CLOSE);
if(distance < shortest){
shortest = distance;
}
fill(0);
textSize(10);
text("Shortest: " + shortest, 250, 550);
fill(0);
textSize(10);
text("Distance: " + distance, 250, 565);
iter++;
Collections.rotate(idx, 1);
save("circles/" + iter + ".png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment