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)); }
public static void main(String[] args) { int n = 10; StdDraw.setCanvasSize(160, 640); StdDraw.setXscale(-1, n + 1); StdDraw.setPenRadius(0.006); double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = StdRandom.uniform(0.0, 1.0); sort(a); }
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); }
public static void main(String[] args) { In in = new In(args[0]); // input file int N = in.readInt(); // N-by-N percolation system // turn on animation mode StdDraw.show(0); // repeatedly read in sites to open and draw resulting system Percolation perc = new Percolation(N); draw(perc, N); StdDraw.show(DELAY); while (!in.isEmpty()) { int i = in.readInt(); int j = in.readInt(); perc.open(i, j); draw(perc, N); StdDraw.show(DELAY); } }
public static void main(String[] args) { StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); StdDraw.show(0); In in = new In(args[0]); int N = in.readInt(); Point[] points = new Point[N]; for (int i = 0; i < N; i++) { int x = in.readInt(); int y = in.readInt(); Point p = new Point(x, y); p.draw(); points[i] = p; } brute(points); StdDraw.show(0); }
// unit test public static void main(String[] args) { /* YOUR CODE HERE */ Point p0 = new Point(1000, 2000); Point p1 = new Point(2000, 2000); Point p2 = new Point(4000, 1000); StdOut.println("Slope of P0: " + p0 + " to P1: " + p1 + " is " + p0.slopeTo(p1)); StdOut.println("Slope of P0: " + p0 + " to P2: " + p2 + " is " + p0.slopeTo(p2)); StdOut.println("Compare P1: " + p1 + " and P2: " + p2 + " is " + p1.compareTo(p2)); // StdOut.println("Compare slope of P0: " + p0 + " to P1: " + p1 + " and P2: " + p2 + " is " + // p1.compareTo(p2)); // draw the points StdDraw.show(0); StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); p0.draw(); p1.draw(); p2.draw(); p0.drawTo(p1); p0.drawTo(p2); StdDraw.show(); }
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(); }
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]); }
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); }
public void draw() { StdDraw.setPenColor(color); StdDraw.filledCircle(rx, ry, radius); }
/** * 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); }
/** Draws this point to standard draw. */ public void draw() { /* DO NOT MODIFY */ StdDraw.point(x, y); }
public static void main(String[] args) { String filename = args[0]; In in = new In(filename); StdDraw.show(0); // initialize the data structures with N points from standard input PointSET brute = new PointSET(); KdTree kdtree = new KdTree(); while (!in.isEmpty()) { double x = in.readDouble(); double y = in.readDouble(); Point2D p = new Point2D(x, y); kdtree.insert(p); brute.insert(p); } double x0 = 0.0, y0 = 0.0; // initial endpoint of rectangle double x1 = 0.0, y1 = 0.0; // current location of mouse boolean isDragging = false; // is the user dragging a rectangle // draw the points StdDraw.clear(); StdDraw.setPenColor(StdDraw.BLACK); StdDraw.setPenRadius(.01); brute.draw(); while (true) { StdDraw.show(40); // user starts to drag a rectangle if (StdDraw.mousePressed() && !isDragging) { x0 = StdDraw.mouseX(); y0 = StdDraw.mouseY(); isDragging = true; continue; } // user is dragging a rectangle else if (StdDraw.mousePressed() && isDragging) { x1 = StdDraw.mouseX(); y1 = StdDraw.mouseY(); continue; } // mouse no longer pressed else if (!StdDraw.mousePressed() && isDragging) { isDragging = false; } RectHV rect = new RectHV(Math.min(x0, x1), Math.min(y0, y1), Math.max(x0, x1), Math.max(y0, y1)); // draw the points StdDraw.clear(); StdDraw.setPenColor(StdDraw.BLACK); StdDraw.setPenRadius(.01); brute.draw(); // draw the rectangle StdDraw.setPenColor(StdDraw.BLACK); StdDraw.setPenRadius(); rect.draw(); // draw the range search results for brute-force data structure in // red StdDraw.setPenRadius(.03); StdDraw.setPenColor(StdDraw.RED); for (Point2D p : brute.range(rect)) p.draw(); // draw the range search results for kd-tree in blue StdDraw.setPenRadius(.02); StdDraw.setPenColor(StdDraw.BLUE); for (Point2D p : kdtree.range(rect)) p.draw(); StdDraw.show(40); } }
// draw N-by-N percolation system public static void draw(Percolation perc, int N) { StdDraw.clear(); StdDraw.setPenColor(StdDraw.BLACK); StdDraw.setXscale(-.05 * N, 1.05 * N); StdDraw.setYscale(-.05 * N, 1.05 * N); // leave a border to write text StdDraw.filledSquare(N / 2.0, N / 2.0, N / 2.0); // draw N-by-N grid int opened = 0; for (int row = 1; row <= N; row++) { for (int col = 1; col <= N; col++) { if (perc.isFull(row, col)) { StdDraw.setPenColor(StdDraw.BOOK_LIGHT_BLUE); opened++; } else if (perc.isOpen(row, col)) { StdDraw.setPenColor(StdDraw.WHITE); opened++; } else StdDraw.setPenColor(StdDraw.BLACK); StdDraw.filledSquare(col - 0.5, N - row + 0.5, 0.45); } } // write status text StdDraw.setFont(new Font("SansSerif", Font.PLAIN, 12)); StdDraw.setPenColor(StdDraw.BLACK); StdDraw.text(.25 * N, -N * .025, opened + " open sites"); if (perc.percolates()) StdDraw.text(.75 * N, -N * .025, "percolates"); else StdDraw.text(.75 * N, -N * .025, "does not percolate"); }
// draw all points to standard draw public void draw() { for (Point2D point2D : root.subSet(LOWER, HIGHER)) { StdDraw.point(point2D.x(), point2D.y()); } }
public static void main(String[] args) { // read the n points from a file In in = new In(args[0]); int n = in.readInt(); Point[] points = new Point[n]; for (int i = 0; i < n; i++) { int x = in.readInt(); int y = in.readInt(); points[i] = new Point(x, y); } // draw the points StdDraw.enableDoubleBuffering(); StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); for (Point p : points) { p.draw(); } StdDraw.show(); // print and draw the line segments FastCollinearPoints collinear = new FastCollinearPoints(points); for (LineSegment segment : collinear.segments()) { StdOut.println(segment); segment.draw(); } StdDraw.show(); }
public static void main(String[] args) { // read the N points from a file args = new String[1]; args[0] = "test/rs1423.txt"; In in = new In(args[0]); int N = in.readInt(); Point[] points = new Point[N]; for (int i = 0; i < N; i++) { int x = in.readInt(); int y = in.readInt(); points[i] = new Point(x, y); } // draw the points StdDraw.show(0); StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); for (Point p : points) { p.draw(); } StdDraw.show(); // print and draw the line segments FastCollinearPoints collinear = new FastCollinearPoints(points); for (LineSegment segment : collinear.segments()) { StdOut.println(segment); segment.draw(); } }
public static void main(String[] args) { String input = "C:/Users/gkoontz/workspace/algoAssignments/src/collinear/equidistant.txt"; // read the N points from a file // In in = new In(args[0]); In in = new In(input); int N = in.readInt(); Point[] points = new Point[N]; for (int i = 0; i < N; i++) { int x = in.readInt(); int y = in.readInt(); points[i] = new Point(x, y); } // draw the points StdDraw.show(0); StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); for (Point p : points) { p.draw(); } StdDraw.show(); // print and draw the line segments // BruteCollinearPoints collinear = new BruteCollinearPoints(points); FastCollinearPoints collinear = new FastCollinearPoints(points); for (LineSegment segment : collinear.segments()) { StdOut.println(segment); segment.draw(); } }