Пример #1
0
  /** 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);
  }
Пример #2
0
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
Пример #3
0
 /**
  * Write the given text string in the current font, centered at <location>.
  *
  * @param location the Point at the center of the text
  * @param s the text
  */
 public static void text(Point2D.Double location, String s) {
   text(location.getX(), location.getY(), s);
 }