Ejemplo n.º 1
0
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   StdDraw.line(.5, .5, .5, .8);
   StdDraw.line(.5, .5, .7, .5);
   StdDraw.line(.5, .8, .7, .5);
   StdDraw.circle(.6, .65, Math.pow(0.0325, 0.5));
 }
Ejemplo n.º 2
0
 private static void show(double[] a, int i, int j) {
   StdDraw.setYscale(-a.length + i + 1, i);
   StdDraw.setPenColor(StdDraw.LIGHT_GRAY);
   for (int k = 0; k < j; k++) StdDraw.line(k, 0, k, a[k] * 0.6);
   StdDraw.setPenColor(StdDraw.BOOK_RED);
   StdDraw.line(j, 0, j, a[j] * 0.6);
   StdDraw.setPenColor(StdDraw.BLACK);
   for (int k = j + 1; k <= i; k++) StdDraw.line(k, 0, k, a[k] * 0.6);
   StdDraw.setPenColor(StdDraw.LIGHT_GRAY);
   for (int k = i + 1; k < a.length; k++) StdDraw.line(k, 0, k, a[k] * 0.6);
 }
Ejemplo n.º 3
0
 private void drawNode(KdNode nd, int turn, double xmin, double ymin, double xmax, double ymax) {
   if (nd == null) return;
   StdDraw.setPenRadius(0.02);
   if (turn == 0) {
     StdDraw.setPenColor(StdDraw.RED);
     StdDraw.line(nd.point.x(), ymin, nd.point.x(), ymax);
     drawNode(nd.left, 1 - turn, xmin, ymin, nd.point.x(), ymax);
     drawNode(nd.right, 1 - turn, nd.point.x(), ymin, xmax, ymax);
   } else {
     StdDraw.setPenColor(StdDraw.BLUE);
     StdDraw.line(xmin, nd.point.y(), xmax, nd.point.y());
     drawNode(nd.left, 1 - turn, xmin, ymin, xmax, nd.point.y());
     drawNode(nd.right, 1 - turn, xmin, nd.point.y(), xmax, ymax);
   }
   StdDraw.setPenColor(StdDraw.BLACK);
   StdDraw.setPenRadius(0.2);
   nd.point.draw();
 }
Ejemplo n.º 4
0
  private void draw(Node x, Orientation orientation) {
    if (x == null) {
      return;
    }

    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.setPenRadius(0.01);
    x.p.draw();

    if (orientation == Orientation.LR) {
      StdDraw.setPenColor(StdDraw.RED);
      StdDraw.setPenRadius(0.001);
      StdDraw.line(x.p.x(), x.rect.ymin(), x.p.x(), x.rect.ymax());
    } else {
      StdDraw.setPenColor(StdDraw.BLUE);
      StdDraw.setPenRadius(0.001);
      StdDraw.line(x.rect.xmin(), x.p.y(), x.rect.xmax(), x.p.y());
    }

    Orientation next = orientation.next();
    draw(x.lb, next);
    draw(x.rt, next);
  }
Ejemplo n.º 5
0
  public static void drawRandConn(int N, double p) {
    StdDraw.setCanvasSize(512, 512);
    StdDraw.setScale(-1.0, 1.0);
    StdDraw.setPenRadius(.025);

    double[][] d = new double[N][2];
    for (int i = 0; i < N; i++) {
      d[i][0] = Math.cos(2 * Math.PI * i / N);
      d[i][1] = Math.sin(2 * Math.PI * i / N);
      StdDraw.point(d[i][0], d[i][1]);
    }

    StdDraw.setPenRadius();
    StdDraw.setPenColor(StdDraw.GRAY);

    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (StdRandom.bernoulli(p)) StdDraw.line(d[i][0], d[i][1], d[j][0], d[j][1]);
  }
Ejemplo n.º 6
0
 /**
  * Draws the line segment between this point and the specified point to standard draw.
  *
  * @param that the other point
  */
 public void drawTo(Point that) {
   /* DO NOT MODIFY */
   StdDraw.line(this.x, this.y, that.x, that.y);
 }