NilsKirchhoff

AoC 2019 - Day 2 - ProcessingSketch (not Working)

Dec 4th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. String fileName = "input.txt";
  2. //String fileName = "testdata.txt";
  3. BufferedReader reader;
  4. String line;
  5. Integer[] currentCoords;
  6. color lineColor;
  7. ArrayList<Integer[]> coords1;
  8. ArrayList<Integer[]> coords2;
  9. IntList hits;
  10.  
  11. void setup() {
  12.   size(600, 600);
  13.   background(0);
  14.   reader = createReader(fileName);
  15.   currentCoords = new Integer[] {0,0};
  16.   lineColor = color(255,0,0);
  17.   coords1 = new ArrayList<Integer[]>();
  18.   coords2 = new ArrayList<Integer[]>();
  19.   hits = new IntList();
  20.  
  21. }
  22.  
  23. void draw() {
  24.  pushMatrix();
  25.  translate(width/2,height/2);
  26.  scale(1);
  27.  for(int i=0; i <= 1; i++){
  28.       line = parseInput(reader);  
  29.       if(line != null) {
  30.         String[] listSplit = split(line, ',');
  31.         for( String value : listSplit ) {
  32.           String direction = value.substring(0, 1);
  33.           int amount = int(value.substring(1));
  34.           for(int j=0; j < amount; j++){
  35.             drawLoc(direction);  
  36.             stroke(lineColor);
  37.             point(currentCoords[0], currentCoords[1]);
  38.             if(i==0)
  39.               coords1.add(new Integer[]{currentCoords[0], currentCoords[1]});
  40.             if(i==1)
  41.               coords2.add(new Integer[]{currentCoords[0], currentCoords[1]});
  42.             }
  43.           }
  44.         }
  45.         lineColor = color(0,0,255);
  46.         currentCoords = new Integer[] {0,0};
  47.         println("first row done " + coords1.size() + " " + coords2.size());
  48.   }
  49.   popMatrix();
  50.  
  51.  for(int i=0; i < coords1.size(); i++) {
  52.    Integer[] linePos1 = coords1.get(i);
  53.    for(int j=0; j < coords2.size(); j++) {
  54.      Integer[] linePos2 = coords2.get(j);
  55.      if(linePos1[0] == linePos2[0] &&  linePos1[1]  == linePos2[1]) {
  56.                   //hits.append(coordValue[0] + (-coordValue[1]));
  57.                   println("hit" + linePos2[0] + " " + linePos2[1]);
  58.      }
  59.    }
  60.  }
  61.  noLoop();
  62.  
  63. }
  64.  
  65. void drawLoc(String direction) {
  66.     switch(direction) {
  67.         case "U":
  68.           currentCoords[1]--;
  69.         break;
  70.         case "D":
  71.           currentCoords[1]++;
  72.         break;
  73.         case "L":
  74.           currentCoords[0]--;
  75.         break;
  76.         case "R":
  77.           currentCoords[0]++;
  78.         break;
  79.   }
  80. }
  81.  
  82. String parseInput(BufferedReader reader) {
  83.   String line;
  84.        try {
  85.         line = reader.readLine();
  86.       }
  87.       catch (IOException e) {
  88.         line = null;
  89.       }  
  90.   return line;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment