예제 #1
0
 /**
  * Draw a filled square of side length 2r, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the square
  * @param y the y-coordinate of the center of the square
  * @param r radius is half the length of any side of the square
  * @throws IllegalArgumentException if r is negative
  */
 public static void filledSquare(double x, double y, double r) {
   if (r < 0) throw new IllegalArgumentException("square side length must be nonnegative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * r);
   double hs = factorY(2 * r);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Rectangle2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
예제 #2
0
 /**
  * Draw filled circle of radius r, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the circle
  * @param y the y-coordinate of the center of the circle
  * @param r the radius of the circle
  * @throws IllegalArgumentException if the radius of the circle is negative
  */
 public static void filledCircle(double x, double y, double r) {
   if (r < 0) throw new IllegalArgumentException("circle radius must be nonnegative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * r);
   double hs = factorY(2 * r);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Ellipse2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
예제 #3
0
 /**
  * Draw a filled rectangle of given half width and half height, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the rectangle
  * @param y the y-coordinate of the center of the rectangle
  * @param halfWidth is half the width of the rectangle
  * @param halfHeight is half the height of the rectangle
  * @throws IllegalArgumentException if halfWidth or halfHeight is negative
  */
 public static void filledRectangle(double x, double y, double halfWidth, double halfHeight) {
   if (halfWidth < 0) throw new IllegalArgumentException("half width must be nonnegative");
   if (halfHeight < 0) throw new IllegalArgumentException("half height must be nonnegative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * halfWidth);
   double hs = factorY(2 * halfHeight);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Rectangle2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
예제 #4
0
 /**
  * Draw an arc of radius r, centered on (x, y), from angle1 to angle2 (in degrees).
  *
  * @param x the x-coordinate of the center of the circle
  * @param y the y-coordinate of the center of the circle
  * @param r the radius of the circle
  * @param angle1 the starting angle. 0 would mean an arc beginning at 3 o'clock.
  * @param angle2 the angle at the end of the arc. For example, if you want a 90 degree arc, then
  *     angle2 should be angle1 + 90.
  * @throws IllegalArgumentException if the radius of the circle is negative
  */
 public static void arc(double x, double y, double r, double angle1, double angle2) {
   if (r < 0) throw new IllegalArgumentException("arc radius must be nonnegative");
   while (angle2 < angle1) angle2 += 360;
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * r);
   double hs = factorY(2 * r);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else
     offscreen.draw(
         new Arc2D.Double(xs - ws / 2, ys - hs / 2, ws, hs, angle1, angle2 - angle1, Arc2D.OPEN));
   draw();
 }
예제 #5
0
 /**
  * Draw an ellipse with given semimajor and semiminor axes, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the ellipse
  * @param y the y-coordinate of the center of the ellipse
  * @param semiMajorAxis is the semimajor axis of the ellipse
  * @param semiMinorAxis is the semiminor axis of the ellipse
  * @throws IllegalArgumentException if either of the axes are negative
  */
 public static void filledEllipse(double x, double y, double semiMajorAxis, double semiMinorAxis) {
   if (semiMajorAxis < 0)
     throw new IllegalArgumentException("ellipse semimajor axis must be nonnegative");
   if (semiMinorAxis < 0)
     throw new IllegalArgumentException("ellipse semiminor axis must be nonnegative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * semiMajorAxis);
   double hs = factorY(2 * semiMinorAxis);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Ellipse2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
예제 #6
0
  /**
   * Draw a point at (x, y).
   *
   * @param x the x-coordinate of the point
   * @param y the y-coordinate of the point
   */
  public static void point(double x, double y) {
    double xs = scaleX(x);
    double ys = scaleY(y);
    double r = penRadius;
    float scaledPenRadius = (float) (r * DEFAULT_SIZE);

    // double ws = factorX(2*r);
    // double hs = factorY(2*r);
    // if (ws <= 1 && hs <= 1) pixel(x, y);
    if (scaledPenRadius <= 1) pixel(x, y);
    else
      offscreen.fill(
          new Ellipse2D.Double(
              xs - scaledPenRadius / 2,
              ys - scaledPenRadius / 2,
              scaledPenRadius,
              scaledPenRadius));
    draw();
  }
예제 #7
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees, rescaled
   * to w-by-h.
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param w the width of the image
   * @param h the height of the image
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws IllegalArgumentException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double w, double h, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    double ws = factorX(w);
    double hs = factorY(h);
    if (ws < 0 || hs < 0) throw new IllegalArgumentException("image " + s + " is corrupt");
    if (ws <= 1 && hs <= 1) pixel(x, y);

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image,
        (int) Math.round(xs - ws / 2.0),
        (int) Math.round(ys - hs / 2.0),
        (int) Math.round(ws),
        (int) Math.round(hs),
        null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
예제 #8
0
 /**
  * Draw picture (gif, jpg, or png) centered on (x, y), rescaled to w-by-h.
  *
  * @param x the center x coordinate of the image
  * @param y the center y coordinate of the image
  * @param s the name of the image/picture, e.g., "ball.gif"
  * @param w the width of the image
  * @param h the height of the image
  * @throws IllegalArgumentException if the width height are negative
  * @throws IllegalArgumentException if the image is corrupt
  */
 public static void picture(double x, double y, String s, double w, double h) {
   Image image = getImage(s);
   double xs = scaleX(x);
   double ys = scaleY(y);
   if (w < 0) throw new IllegalArgumentException("width is negative: " + w);
   if (h < 0) throw new IllegalArgumentException("height is negative: " + h);
   double ws = factorX(w);
   double hs = factorY(h);
   if (ws < 0 || hs < 0) throw new IllegalArgumentException("image " + s + " is corrupt");
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else {
     offscreen.drawImage(
         image,
         (int) Math.round(xs - ws / 2.0),
         (int) Math.round(ys - hs / 2.0),
         (int) Math.round(ws),
         (int) Math.round(hs),
         null);
   }
   draw();
 }