/** Test client. */ public static void main(String[] args) { // final int WINDOW_LENGTH = 600; // final int WINDOW_HEIGHT = 1200; // StdDraw.setCanvasSize(WINDOW_HEIGHT, WINDOW_LENGTH); //pixel size of window StdDraw.setXscale(0, 1.2); StdDraw.setYscale(0, 1.2); StdDraw.square(.2, .8, .1); StdDraw.filledSquare(.8, .8, .2); StdDraw.circle(.8, .2, .2); // draw a blue diamond, radius 0.1 (old method) StdDraw.setPenRadius(); // default radius StdDraw.setPenColor(Colors.BOOK_BLUE); double[] x = {.1, .2, .3, .2}; double[] y = {.2, .3, .2, .1}; StdDraw.filledPolygon(x, y); // draw a cyandiamond, radius 0.1 (new method) StdDraw.setPenColor(Colors.CYAN); StdDraw.filledDiamond(.45, .2, 0.1); // draw a magenta triangle, radius 0.1 StdDraw.setPenColor(Colors.MAGENTA); StdDraw.filledTriangle(.45, 0.4, 0.1); // Green filled rectangle, rotated x degrees StdDraw.setPenColor(Colors.GREEN); StdDraw.filledAngledRectangle(.45, .8, .05, .2, 10); // StdDraw.filledAngledRectangle(0.2, 0.2, 0.2, 0.05, 90); // StdDraw.filledAngledRectangle(0, 0, 0.2, 0.05, 0); StdDraw.setPenColor(Colors.BOOK_RED); StdDraw.setPenRadius(.02); StdDraw.arc(.8, .2, .1, 120, 60); StdDraw.line(0.8, 0.2, 0.8, 0.3); // text StdDraw.setPenRadius(); StdDraw.setPenColor(Colors.BLACK); StdDraw.text(0.2, 0.5, "black text"); StdDraw.setPenColor(Colors.WHITE); StdDraw.text(0.8, 0.8, "white text"); // Edge testing StdDraw.setPenColor(Colors.GRAY); // StdDraw.circle(0, 0, .2); StdDraw.line(0, 0, 0, 1); }
/** * Draw a filled rectangle of given half width and half height, centred at <location> and rotated * by d degrees. * * @param location the Point at the centre of the rectangle * @param halfWidth is half the width of the rectangle * @param halfHeight is half the height of the rectangle * @param degrees is the rotation of the rectangle with 3 o'clock being 0 degrees and 12 o'clock * being 270 degrees * @throws RuntimeException if halfWidth or halfHeight is negative */ public static void filledAngledRectangle( Point2D.Double location, double halfWidth, double halfHeight, double degrees) { filledAngledRectangle(location.getX(), location.getY(), halfWidth, halfHeight, degrees); }