Beispiel #1
0
    private static void drawChain(
        GrandFinale.Graph g, GrandFinale.Node n, List<GrandFinale.Node> ignore) {
      MazeGridPanel panel = getPanel();
      Color c = panel.getGraphics().getColor();
      Graphics2D g2 = (Graphics2D) panel.getGraphics();
      Font fOld = g2.getFont();
      g2.setFont(new Font("Arial", Font.BOLD, fOld.getSize()));
      ignore.add(n);

      Set<GrandFinale.Edge> edges = g.getEdges(n);
      if (edges == null) {
        return;
      }
      for (GrandFinale.Edge e : edges) {
        GrandFinale.Node b = e.other(n);
        if (ignore.contains(b)) {
          continue;
        }
        int hs = b.hashCode();
        g2.setColor(new Color(((hs << 13) + (hs << 5) + hs) & 0xFFFFFFFF));
        g2.setStroke(new BasicStroke(5));
        Point pos1 = offset(panel, n.getPoint(), 2, 2);
        Point pos2 = offset(panel, b.getPoint(), 2, 2);
        g2.draw(new Line2D.Float(pos1.x, pos1.y, pos2.x, pos2.y));
        g2.setColor(Color.red);
        Point p = new Point((pos1.x + pos2.x) / 2, (pos1.y + pos2.y) / 2);
        g2.drawString(String.valueOf(e.getWeight()), p.x, p.y);
        ignore.add(b);
        drawChain(g, b, ignore);
      }
      g2.setFont(fOld);
      g2.setColor(c);
    }
Beispiel #2
0
 public static void drawGraph(GrandFinale.Graph g, IRobot r) {
   if (!enable.getState()) {
     return;
   }
   drawChain(g, g.getNodeAt(r.getMaze().getStart()), new ArrayList<>());
 }