示例#1
0
  /** Test client. */
  public static void main(String[] args) {

    // set the scale of the coordinate system
    StdDraw.setXscale(0, 10);
    StdDraw.setYscale(0, 10);

    // Draw line
    StdDraw.line(1, 1, 8, 8);

    // Draw square
    StdDraw.setPenColor(StdDraw.RED);
    StdDraw.setPenRadius(.01);
    StdDraw.square(3, 3, 2);

    // Draw filled Square
    StdDraw.setPenColor(StdDraw.BLUE);
    StdDraw.filledSquare(5, 8, 2);

    // Draw Circle
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.setPenRadius();
    StdDraw.circle(5, 5, 2);

    // text
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.text(6, 1, "black text");
  }
示例#2
0
 public void draw() {
   StdDraw.setPenColor(Color.BLACK);
   StdDraw.setPenRadius(0.005);
   StdDraw.setYscale(-1, root.height + 2);
   StdDraw.setXscale(-1, root.N + 1);
   TreePosition rootTree = draw(root, 0, root.height);
   drawNode(rootTree, root);
 }
示例#3
0
  private TreePosition draw(Node x, double leftBorder, double h) {
    if (x == null) {
      StdDraw.setPenRadius(0.02);
      StdDraw.point(leftBorder, h);
      StdDraw.setPenRadius(0.005);
      return new TreePosition(leftBorder, h, leftBorder, leftBorder + 1);
    }
    TreePosition leftTree = draw(x.left, leftBorder, h - 1);
    TreePosition rightTree = draw(x.right, leftTree.right, h - 1);
    TreePosition xTree =
        new TreePosition((leftTree.x + rightTree.x) / 2, h, leftTree.left, rightTree.right);
    StdDraw.line(leftTree.x, leftTree.y, xTree.x, xTree.y);
    StdDraw.line(rightTree.x, rightTree.y, xTree.x, xTree.y);

    if (x.left != null) drawNode(leftTree, x.left);
    if (x.right != null) drawNode(rightTree, x.right);
    return xTree;
  }
示例#4
0
  /** Test client. */
  public static void main(String[] args) {
    StdDraw.square(.2, .8, .1);
    StdDraw.filledSquare(.8, .8, .2);
    StdDraw.circle(.8, .2, .2);

    StdDraw.setPenColor(StdDraw.BOOK_RED);
    StdDraw.setPenRadius(.02);
    StdDraw.arc(.8, .2, .1, 200, 45);

    // draw a blue diamond
    StdDraw.setPenRadius();
    StdDraw.setPenColor(StdDraw.BOOK_BLUE);
    double[] x = {.1, .2, .3, .2};
    double[] y = {.2, .3, .2, .1};
    StdDraw.filledPolygon(x, y);

    // text
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.text(0.2, 0.5, "black text");
    StdDraw.setPenColor(StdDraw.WHITE);
    StdDraw.text(0.8, 0.8, "white text");
  }