Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees
   *
   * @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 degrees is the number of degrees to rotate counterclockwise
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");

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

    draw();
  }
Exemplo n.º 3
0
 protected void drawString(Graphics2D g2, double x, double y, double theta) {
   // Transform to the requested location.
   g2.translate(x, y);
   // Rotate by the requested angle.
   g2.rotate(theta);
   // Draw the first part of the string.
   String first = mMessage.substring(0, mSplit);
   float width = drawBoxedString(g2, first, Color.white, Color.red, 0);
   // Draw the second part of the string.
   String second = mMessage.substring(mSplit);
   drawBoxedString(g2, second, Color.blue, Color.white, width);
   // Undo the transformations.
   g2.rotate(-theta);
   g2.translate(-x, -y);
 }
Exemplo n.º 4
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 RuntimeException 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 RuntimeException("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();
  }