public static void main(String[] args) { int N = 100; StdDraw.setXscale(0, N); StdDraw.setYscale(0, N * N); StdDraw.setPenRadius(.01); for (int i = 0; i <= N; i++) { StdDraw.point(i, i); StdDraw.point(i, i * i); StdDraw.point(i, i * Math.log(i)); } }
public void draw() { // draw all of the points to standard draw for (Point2D point : set) { StdDraw.point(point.x(), point.y()); } StdDraw.show(); }
public static void main(String[] args) { StdDraw.setPenRadius(0.05); StdDraw.setPenColor(StdDraw.BLUE); StdDraw.point(0.5, 0.5); StdDraw.setPenColor(StdDraw.MAGENTA); StdDraw.line(0.2, 0.2, 0.8, 0.2); }
/** Plot points (i, a[i]) to standard draw. */ public static void plotPoints(double[] a) { final int N = a.length; StdDraw.setXscale(0, N - 1); StdDraw.setPenRadius(1.0 / (3.0 * N)); for (int i = 0; i < N; i++) { StdDraw.point(i, a[i]); } }
private static void drawGraphs() { int N = 100; double pointRadius = 0.005; double lineRadius = 0.001; StdDraw.setXscale(0, N); StdDraw.setYscale(0, 10 * N); StdDraw.setPenRadius(pointRadius); StdDraw.setPenColor(Color.black); // Google "Java Color"; the first link gives all the colors StdDraw.line(0, 0, 0, 10 * N); StdDraw.line(0, 0, N, 0); double prevX, prevY; // This will graph runBSTInsertion StdDraw.setPenColor(Color.blue); prevX = 0; prevY = 0; for (int i = 1; i <= N; i++) { int y = runBSTInsertion(i); StdDraw.setPenRadius(pointRadius); StdDraw.point(i, y); StdDraw.setPenRadius(lineRadius); StdDraw.line(prevX, prevY, i, y); prevX = i; prevY = y; } // this will run our graph for C*log*(N), where the C = 2.5. And the graph is orange double C = 2.6; double N1 = 0.1; StdDraw.setPenColor(Color.green); prevX = 0; prevY = 0; for (int i = 1; i <= 100; i++) { StdDraw.setPenRadius(0.001); StdDraw.line( prevX, prevY, i, C * Math.log(i) + N1); // this is the function C*log(N) applied to i StdDraw.setPenRadius(0.005); StdDraw.point(i, C * Math.log(i)); prevX = i; prevY = C * Math.log(i) + N1; } }
// draw all points to standard draw public void draw() { LinkedList<Node> arr = new LinkedList<Node>(); arr.add(this.root); while (!arr.isEmpty()) { Node tp = arr.pollFirst(); StdDraw.point(tp.getP().x(), tp.getP().y()); if (null != tp.getLb()) { arr.add(tp.getLb()); } if (null != tp.getRt()) { arr.add(tp.getRt()); } } }
public static void main(String[] args) { // Plot T iterations of IFS on StdIn int T = Integer.parseInt(args[0]); double[] dist = StdArrayIO.readDouble1D(); double[][] cx = StdArrayIO.readDouble2D(); double[][] cy = StdArrayIO.readDouble2D(); double x = 0.0, y = 0.0; for (int t = 0; t < T; t++) { // plot 1 iteration int r = StdRandom.discrete(dist); double x0 = cx[r][0] * x + cx[r][1] * y + cx[r][2]; double y0 = cy[r][0] * x + cy[r][1] * y + cy[r][2]; x = x0; y = y0; StdDraw.point(x, y); } }
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; }
public static void main(final String[] args) { // read in bounding box and rescale final double xmin = StdIn.readDouble(); final double ymin = StdIn.readDouble(); final double xmax = StdIn.readDouble(); final double ymax = StdIn.readDouble(); StdDraw.setXscale(xmin, xmax); StdDraw.setYscale(ymin, ymax); // turn on animation mode to defer displaying all of the points // StdDraw.show(0); // plot points, one at a time while (!StdIn.isEmpty()) { final double x = StdIn.readDouble(); final double y = StdIn.readDouble(); StdDraw.point(x, y); } // display all of the points now // StdDraw.show(0); }
// plot this point to standard drawing public void draw() { /* DO NOT MODIFY */ StdDraw.point(x, y); }
public void draw() { // draw this point StdDraw.setPenRadius(0.005); StdDraw.point(x, y); }
// draw this point public void draw() { StdDraw.point(this.x, this.y); }