Esempio n. 1
0
 /**
  * @param tn - TreeNode object
  * @param even - Vertical or horizontal cuts
  * @param left - left or right
  * @param pivot - Pivot point This function recursively draws the binary tree and displays how the
  *     tree slices the unit square. It works by sending it the current node to draw, whether or
  *     not it is a vertical cut, whether or not it is a left node, and a "pivot" point. The pivot
  *     point tells the method where to start and stop the line.
  */
 private void drawPoints(TreeNode tn, boolean even, boolean left, double pivot) {
   if (tn == null) return;
   StdDraw.setPenColor();
   // StdDraw.filledCircle(tn.p.x(), tn.p.y(), .005);
   if (even) { // Vertical cuts
     StdDraw.setPenColor(Color.red);
     if (left) {
       StdDraw.line(tn.p.x(), 0, tn.p.x(), pivot);
     } else {
       StdDraw.line(tn.p.x(), pivot, tn.p.x(), 1);
     }
     pivot = tn.p.x();
   } else { // Horizontal cuts
     StdDraw.setPenColor(Color.blue);
     if (left) {
       StdDraw.line(0, tn.p.y(), pivot, tn.p.y());
     } else {
       StdDraw.line(pivot, tn.p.y(), 1, tn.p.y());
     }
     pivot = tn.p.y();
   }
   StdDraw.setPenColor();
   StdDraw.filledCircle(tn.p.x(), tn.p.y(), .007);
   drawPoints(tn.left, !even, true, pivot);
   drawPoints(tn.right, !even, false, pivot);
 } // End drawPoints() function
Esempio n. 2
0
  public void drawGame() {
    StdDraw.clear(StdDraw.GRAY);

    // Set Color
    StdDraw.setPenColor(StdDraw.YELLOW);
    // Set Font
    setFont(new Font("SansSerif", Font.PLAIN, 32));
    // X, Y, String, rotation degree
    // Write String
    this.text(1 - 0.3, 1 - 0.1, blockP.x + ", " + blockP.y, 0);
    // Set Color
    StdDraw.setPenColor(StdDraw.ORANGE);
    // Set Font
    setFont(new Font("SansSerif", Font.PLAIN, 50));
    // Write String
    this.text(1 - 0.3, 1 - 0.3, "START!", 20);

    StdDraw.setPenColor(StdDraw.BLACK);

    for (int i = 0; i < map.length; i++) {
      for (int j = 0; j < map[i].length; j++) {
        if (map[i][j] > 0) {
          Point2D vLoc = map2Visual(i, j);
          System.out.println(i + ", " + j + ", " + vLoc);
          StdDraw.filledCircle(vLoc.getX(), vLoc.getY(), radius);
        }
      }
    }
  }
Esempio n. 3
0
 private void drawNode(TreePosition p, Node x) {
   StdDraw.setPenColor(Color.GREEN);
   StdDraw.filledCircle(p.x, p.y, 0.3);
   StdDraw.setPenColor(Color.RED);
   StdDraw.text(p.x, p.y, x.key.toString());
   StdDraw.setPenColor(Color.BLACK);
 }