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); } } } }
/** * @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
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); }
/** 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"); }
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); }
/** 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"); }