String fileName = "input.txt";
//String fileName = "testdata.txt";
BufferedReader reader;
String line;
Integer[] currentCoords;
color lineColor;
ArrayList<Integer[]> coords1;
ArrayList<Integer[]> coords2;
IntList hits;
void setup() {
size(600, 600);
background(0);
reader = createReader(fileName);
currentCoords = new Integer[] {0,0};
lineColor = color(255,0,0);
coords1 = new ArrayList<Integer[]>();
coords2 = new ArrayList<Integer[]>();
hits = new IntList();
}
void draw() {
pushMatrix();
translate(width/2,height/2);
scale(1);
for(int i=0; i <= 1; i++){
line = parseInput(reader);
if(line != null) {
String[] listSplit = split(line, ',');
for( String value : listSplit ) {
String direction = value.substring(0, 1);
int amount = int(value.substring(1));
for(int j=0; j < amount; j++){
drawLoc(direction);
stroke(lineColor);
point(currentCoords[0], currentCoords[1]);
if(i==0)
coords1.add(new Integer[]{currentCoords[0], currentCoords[1]});
if(i==1)
coords2.add(new Integer[]{currentCoords[0], currentCoords[1]});
}
}
}
lineColor = color(0,0,255);
currentCoords = new Integer[] {0,0};
println("first row done " + coords1.size() + " " + coords2.size());
}
popMatrix();
for(int i=0; i < coords1.size(); i++) {
Integer[] linePos1 = coords1.get(i);
for(int j=0; j < coords2.size(); j++) {
Integer[] linePos2 = coords2.get(j);
if(linePos1[0] == linePos2[0] && linePos1[1] == linePos2[1]) {
//hits.append(coordValue[0] + (-coordValue[1]));
println("hit" + linePos2[0] + " " + linePos2[1]);
}
}
}
noLoop();
}
void drawLoc(String direction) {
switch(direction) {
case "U":
currentCoords[1]--;
break;
case "D":
currentCoords[1]++;
break;
case "L":
currentCoords[0]--;
break;
case "R":
currentCoords[0]++;
break;
}
}
String parseInput(BufferedReader reader) {
String line;
try {
line = reader.readLine();
}
catch (IOException e) {
line = null;
}
return line;
}
Comments