예제 #1
0
  /**
   * paintComponent which paints the component. Flips if Status is normalRotation.
   *
   * @param _graphics the graphics which are painted.
   */
  @Override
  public final void paintComponent(final Graphics _graphics) {

    // initialize values
    Graphics2D g2d = (Graphics2D) _graphics;
    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) origXform.clone();

    // center of rotation is center of the panel
    int xRot = this.getWidth() / 2;
    int yRot = this.getHeight() / 2;

    // fetch rotation from Status
    double rotation = 0;

    // if not normal rotation
    if (!State.isNormalRotation()) {
      final int filpRotation = 180;
      rotation = filpRotation;
    }

    // rotate the image and draw the image to panel
    newXform.rotate(Math.toRadians(rotation), xRot, yRot);
    g2d.setTransform(newXform);
    super.paintComponent(g2d);
    g2d.setTransform(origXform);
  }
  /**
   * Renders an image on the device
   *
   * @param graphics the image location on the screen, x coordinate
   * @param x the image location on the screen, y coordinate
   * @param y the image
   * @param image DOCUMENT ME!
   * @param rotation the image rotatation
   * @param opacity DOCUMENT ME!
   */
  private void renderImage(
      Graphics2D graphics,
      double x,
      double y,
      BufferedImage image,
      double rotation,
      float opacity) {
    if (LOGGER.isLoggable(Level.FINEST)) {
      LOGGER.finest("drawing Image @" + x + "," + y);
    }

    AffineTransform markAT = new AffineTransform();
    markAT.translate(x, y);
    markAT.rotate(rotation);
    markAT.translate(-image.getWidth() / 2.0, -image.getHeight() / 2.0);

    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

    Object interpolation = graphics.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
    if (interpolation == null) {
      interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
    }
    try {
      graphics.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics.drawRenderedImage(image, markAT);
    } finally {
      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);
    }
  }
예제 #3
0
    @Override
    void nakresli() {
      vystreduj();

      // Area a1 = new Area([triangle 0,0 => 8,0 => 0,8]);
      // Area a2 = new Area([triangle 0,0 => 8,0 => 8,8]);
      // a1.add(a2);
      final Area poly =
          new Area(new Polygon(new int[] {0, 1, 1, 5, 0}, new int[] {0, 1, 7, 7, 12}, 5));
      final Area a = new Area();

      final AffineTransform rotace = new AffineTransform();
      rotace.rotate(Math.PI / 2);
      final AffineTransform zrcadlo = new AffineTransform();
      zrcadlo.scale(1, -1);
      for (int i = 0; i < 4; i++) {
        a.transform(zrcadlo);
        a.add(poly);
        a.transform(zrcadlo);
        a.add(poly);
        a.transform(rotace);
      }
      g.setColor(Color.GREEN);
      g.fill(a);
      g.setColor(Color.BLACK);
      g.draw(a);
    }
예제 #4
0
 @Override
 public void rotate(Point2D point, double theta) {
   final AffineTransform transform = new AffineTransform();
   transform.rotate(theta, point.getX(), point.getY());
   Point2D point2D = transform.transform(getLocation(), null);
   setLocation(point2D);
 }
예제 #5
0
  // TODO currently allows for collisions if same name & different filetype
  public void loadImage(String path) {
    BufferedImage readImage = null;
    try {
      readImage = ImageIO.read(new File("images/" + path));
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (readImage != null) {
      BufferedImage aImages[] = new BufferedImage[8];
      BufferedImage image =
          new BufferedImage(
              readImage.getWidth(), readImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
      Graphics g = image.getGraphics();
      g.drawImage(readImage, 0, 0, null);
      for (int i = 0; i < 8; i++) {
        AffineTransform trans = new AffineTransform();
        trans.translate(image.getWidth() / 2, image.getHeight() / 2);
        trans.rotate(Math.PI * i / 4.0);
        trans.translate(-image.getWidth() / 2, -image.getHeight() / 2);
        AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
        aImages[i] =
            new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        op.filter(image, aImages[i]);
      }

      images.add(
          new Asset(
              path.substring(0, path.length() - 4), aImages)); // assumes standard 3 letter postfix
    }
  }
예제 #6
0
 public void Draw(Graphics2D gr) {
   AffineTransform transform = new AffineTransform();
   transform.rotate(Direction, x + width / 2, y + height / 2);
   transform.translate(x, y);
   switch (color) {
     case RED:
       gr.drawImage(image.getSubimage(0, 0, 50, 50), transform, null);
       break;
     case YELLOW:
       gr.drawImage(image.getSubimage(50, 0, 50, 50), transform, null);
       break;
     case PURPLE:
       gr.drawImage(image.getSubimage(100, 0, 50, 50), transform, null);
       break;
     case WHITE:
       gr.drawImage(image.getSubimage(150, 0, 50, 50), transform, null);
       break;
     case GREEN:
       gr.drawImage(image.getSubimage(200, 0, 50, 50), transform, null);
       break;
     case BLUE:
       gr.drawImage(image.getSubimage(250, 0, 50, 50), transform, null);
       break;
   }
   gun.Draw(gr);
 }
예제 #7
0
파일: Well.java 프로젝트: RoboSquirt/java
  /**
   * Called by the dispatcher, tells its well to paint itself at the proper location.
   *
   * @param g - graphics to paint on
   * @param sF - scale factor from cm to pixels
   */
  public void paint(Graphics g, double sF, boolean isRotated) {

    // get the graphics objects
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform at = new AffineTransform();

    // draw well's outline
    at.translate(parentPlate.getTLcorner().getX() * sF, parentPlate.getTLcorner().getY() * sF);
    if (isRotated) {
      at.translate(parentPlate.getPlateSpecs().getBorderDimensions().getY() * sF, 0);
      at.rotate(Math.PI / 2);
    }
    at.translate(
        (relativeLocation.getX() - diameter / 2) * sF,
        (relativeLocation.getY() - diameter / 2) * sF);
    at.scale(sF, sF);

    g2d.setTransform(at);
    g2d.setColor(Color.BLACK);
    g2d.drawOval(0, 0, (int) diameter, (int) diameter);

    // highlight well if it is selected
    if (isSelected) {
      g2d.setColor(Color.LIGHT_GRAY);
      g2d.fillOval(0, 0, (int) diameter, (int) diameter);
    }
  }
예제 #8
0
 public void tree(Graphics2D g2d, double size, int phase) {
   g2d.setColor(colors[phase % 3]);
   new TextLayout(theT.toString(), theFont, g2d.getFontRenderContext()).draw(g2d, 0.0f, 0.0f);
   if (size > 10.0) {
     AffineTransform at = new AffineTransform();
     at.setToTranslation(Twidth, -0.1);
     at.scale(0.6, 0.6);
     g2d.transform(at);
     size *= 0.6;
     new TextLayout(theR.toString(), theFont, g2d.getFontRenderContext()).draw(g2d, 0.0f, 0.0f);
     at.setToTranslation(Rwidth + 0.75, 0);
     g2d.transform(at);
     Graphics2D g2dt = (Graphics2D) g2d.create();
     at.setToRotation(-Math.PI / 2.0);
     g2dt.transform(at);
     tree(g2dt, size, phase + 1);
     g2dt.dispose();
     at.setToTranslation(.75, 0);
     at.rotate(-Math.PI / 2.0);
     at.scale(-1.0, 1.0);
     at.translate(-Twidth, 0);
     g2d.transform(at);
     tree(g2d, size, phase);
   }
   g2d.setTransform(new AffineTransform());
 }
예제 #9
0
  public void drawPoolOrLane(String name, int x, int y, int width, int height) {
    g.drawRect(x, y, width, height);

    // Add the name as text, vertical
    if (name != null && name.length() > 0) {
      // Include some padding
      int availableTextSpace = height - 6;

      // Create rotation for derived font
      AffineTransform transformation = new AffineTransform();
      transformation.setToIdentity();
      transformation.rotate(270 * Math.PI / 180);

      Font currentFont = g.getFont();
      Font theDerivedFont = currentFont.deriveFont(transformation);
      g.setFont(theDerivedFont);

      String truncated = fitTextToWidth(name, availableTextSpace);
      int realWidth = fontMetrics.stringWidth(truncated);

      g.drawString(
          truncated,
          x + 2 + fontMetrics.getHeight(),
          3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2);
      g.setFont(currentFont);
    }
  }
예제 #10
0
  private ImageData writeImageMjpeg(OutputStream os) throws IOException {

    final LimitFinder limitFinder = new LimitFinder(TextBlockUtils.getDummyStringBounder(), true);
    udrawable.drawU(limitFinder);
    final Dimension2D dim =
        new Dimension2DDouble(
            limitFinder.getMaxX() + 1 + margin1 + margin2,
            limitFinder.getMaxY() + 1 + margin1 + margin2);

    final File f = new File("c:/tmp.avi");

    final int nbframe = 100;

    final MJPEGGenerator m =
        new MJPEGGenerator(
            f, getAviImage(null).getWidth(null), getAviImage(null).getHeight(null), 12.0, nbframe);
    for (int i = 0; i < nbframe; i++) {
      // AffineTransform at = AffineTransform.getRotateInstance(1.0);
      AffineTransform at =
          AffineTransform.getTranslateInstance(dim.getWidth() / 2, dim.getHeight() / 2);
      at.rotate(90.0 * Math.PI / 180.0 * i / 100);
      at.translate(-dim.getWidth() / 2, -dim.getHeight() / 2);
      // final AffineTransform at = AffineTransform.getTranslateInstance(i, 0);
      // final ImageIcon ii = new ImageIcon(getAviImage(at));
      // m.addImage(ii.getImage());
      throw new UnsupportedOperationException();
    }
    m.finishAVI();

    FileUtils.copyToStream(f, os);

    return new ImageDataSimple(dim);
  }
  /**
   * A static method for drawing an image (adapted from my first assignment)
   *
   * @param x horizontal position
   * @param y vertical position
   * @param w the scaled image width
   * @param h the scaled image height
   * @param angle the angle of rotation of the image
   * @param hflip whether or not to flip the image horizontally
   * @param vflip whether or not to flip the image vertically
   * @param canvas the image to draw
   * @param screen the destination to render to
   */
  public static void drawImage(
      double x,
      double y,
      double w,
      double h,
      double angle,
      boolean hflip,
      boolean vflip,
      BufferedImage canvas,
      Graphics2D screen) {
    AffineTransform oldTransform = screen.getTransform();
    double widthRatio = (double) w / (double) canvas.getWidth();
    double heightRatio = (double) h / (double) canvas.getHeight();

    AffineTransform affine = new AffineTransform();
    affine.translate(x, y);
    affine.scale(widthRatio, heightRatio);
    affine.scale((hflip ? -1 : 1) * 1.0, (vflip ? -1 : 1) * 1.0);
    affine.rotate(angle);
    affine.translate((double) -canvas.getWidth() / 2.0, (double) -canvas.getHeight() / 2.0);

    screen.transform(affine);

    screen.drawImage(canvas, 0, 0, null);
    screen.setTransform(oldTransform);
  }
예제 #12
0
 protected Point rotateAboutCentre(Point target, double radians) {
   Point result = new Point();
   AffineTransform rotation = new AffineTransform(); // 'tis affine transform, cap'n
   rotation.rotate(radians, this.centre.x, this.centre.y);
   rotation.transform(target, result);
   return result;
 }
예제 #13
0
  private void paintScaledTriangle(
      Graphics g, double x, double y, double size, int direction, boolean isEnabled) {
    size = Math.max(size, 2);
    Path2D.Double path = new Path2D.Double();
    path.moveTo(-size, size / 2);
    path.lineTo(size, size / 2);
    path.lineTo(0, -size / 2);
    path.closePath();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(Math.PI * (direction - 1) / 4);
    path.transform(affineTransform);

    Graphics2D g2d = (Graphics2D) g;
    double tx = x + size / 2;
    double ty = y + size / 2;
    g2d.translate(tx, ty);
    Color oldColor = g.getColor();
    if (!isEnabled) {
      g2d.translate(1, 0);
      g2d.setColor(highlight);
      g2d.fill(path);
      g2d.translate(-1, 0);
    }
    g2d.setColor(isEnabled ? darkShadow : shadow);
    g2d.fill(path);
    g2d.translate(-tx, -ty);
    g2d.setColor(oldColor);
  }
예제 #14
0
 public void update() {
   x += Math.cos(heading) * speed;
   y += Math.sin(heading) * speed;
   rect.setLocation((int) Math.round(x), (int) Math.round(y));
   affineTransform.setToTranslation(x, y);
   affineTransform.rotate(heading + (Math.PI / 2));
 }
  public void test010() {
    final float width = 3;
    final float height = 0;
    final Point2D.Float zero = new Point2D.Float(0, 0);
    final Point2D.Float ch = new Point2D.Float(0, 2);
    final Point2D.Float cb = new Point2D.Float(0, -1);
    final float h = ch.y - cb.y;
    final float sca = width / h;

    AffineTransform mat = new AffineTransform();
    mat.translate(width / 2, height / 2);
    mat.scale(sca, sca);
    mat.rotate(Math.PI / 2);
    mat.translate(0, -(ch.y + cb.y) / 2);

    final Point2D.Float cht = new Point2D.Float(0, 0);
    final Point2D.Float cbt = new Point2D.Float(0, 0);
    final Point2D.Float zerot = new Point2D.Float(0, 0);
    mat.transform(ch, cht);
    mat.transform(cb, cbt);
    mat.transform(zero, zerot);
    print("Hog :", cht);
    print("Back:", cbt);
    print("0,0 :", zerot);

    // assertEquals("", (float) 0, p.x, (float) 1e-1);
    // assertEquals("", (float) 0, p.y, (float) 1e-1);
  }
예제 #16
0
  /**
   * Renders an image on the device
   *
   * @param tx the image location on the screen, x coordinate
   * @param ty the image location on the screen, y coordinate
   * @param img the image
   * @param rotation the image rotatation
   */
  private static void renderImage(
      Graphics2D graphics, double x, double y, Image image, double rotation, float opacity) {
    AffineTransform temp = graphics.getTransform();
    AffineTransform markAT = new AffineTransform();
    Point2D mapCentre = new java.awt.geom.Point2D.Double(x, y);
    Point2D graphicCentre = new java.awt.geom.Point2D.Double();
    temp.transform(mapCentre, graphicCentre);
    markAT.translate(graphicCentre.getX(), graphicCentre.getY());

    double shearY = temp.getShearY();
    double scaleY = temp.getScaleY();

    double originalRotation = Math.atan(shearY / scaleY);

    markAT.rotate(rotation);
    graphics.setTransform(markAT);
    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

    // we moved the origin to the centre of the image.
    graphics.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null);

    graphics.setTransform(temp);

    return;
  }
예제 #17
0
  public void drawConditionalSequenceFlowIndicator(Line2D.Double line) {
    int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7);
    int halfOfHorizontal = horizontal / 2;
    int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2;

    Polygon conditionalIndicator = new Polygon();
    conditionalIndicator.addPoint(0, 0);
    conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical);
    conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH);
    conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical);

    AffineTransform transformation = new AffineTransform();
    transformation.setToIdentity();
    double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1);
    transformation.translate(line.x1, line.y1);
    transformation.rotate((angle - Math.PI / 2d));

    AffineTransform originalTransformation = g.getTransform();
    g.setTransform(transformation);
    g.draw(conditionalIndicator);

    Paint originalPaint = g.getPaint();
    g.setPaint(CONDITIONAL_INDICATOR_COLOR);
    g.fill(conditionalIndicator);

    g.setPaint(originalPaint);
    g.setTransform(originalTransformation);
  }
  public static BufferedImage rotateImage(BufferedImage img, int angle, Graphics2D g) {
    AffineTransform at = new AffineTransform();
    at.rotate(Math.toRadians(angle), img.getWidth() / 2, img.getHeight() / 2);

    g.drawImage(img, at, null);

    return img;
  }
 private static AffineTransform nonIdentityAffineTransform() {
   AffineTransform transf = new AffineTransform();
   transf.translate(3.0, 5.0);
   transf.rotate(2.0);
   transf.scale(6.0, 7.0);
   transf.shear(3.5, 4.5);
   return transf;
 }
예제 #20
0
 // Update the current AffineTransform
 private void updateAffineTransform() {
   affineTransform.setToIdentity();
   affineTransform.translate(getWidth() * 0.5, getHeight() * 0.5);
   affineTransform.scale(scale, scale);
   affineTransform.translate(transX, transY);
   affineTransform.rotate(rotateAngle);
   affineTransform.translate(-modelCenter.x, -modelCenter.y);
 }
예제 #21
0
 public AffineTransform getPixelToMapTransform() {
   AffineTransform transform = new AffineTransform();
   transform.translate(getEasting(), getNorthing());
   transform.scale(getPixelSizeX(), -getPixelSizeY());
   transform.rotate(Math.toRadians(-getOrientation()));
   transform.translate(-getPixelX(), -getPixelY());
   return transform;
 }
예제 #22
0
파일: Tools.java 프로젝트: Holdlen2DH/nest
 public static RenderedOp transformImage(
     RenderedImage image, double x0, double y0, double theta, double scale) {
   final AffineTransform transform = new AffineTransform();
   transform.rotate(theta, -0.5f * image.getWidth(), -0.5f * image.getHeight());
   transform.scale(scale, scale);
   transform.translate(x0, y0);
   return transformImage(image, transform);
 }
예제 #23
0
 public static AffineTransform makeComplexAT() {
   AffineTransform at = new AffineTransform();
   at.scale(2.5, -3.0);
   at.rotate(Math.PI / 4.0);
   at.shear(1.0, -3.0);
   at.translate(25.0, 12.5);
   return at;
 };
예제 #24
0
  /**
   * Returns the contour of the ellipse.
   *
   * @return A new {@code GeneralPath} object containing the contour of the ellipse.
   */
  public GeneralPath contour() {

    final GeneralPath gp =
        new GeneralPath(new Ellipse2D.Double(x - major, y - minor, 2 * major, 2 * minor));
    final AffineTransform at = new AffineTransform();
    at.rotate(angle, x, y);
    gp.transform(at);
    return gp;
  }
예제 #25
0
  public void render(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform xform = new AffineTransform();
    xform.setTransform(identity);
    xform.translate(getVector().getX(), getVector().getY());
    xform.rotate(getVector().getBearing() + Math.PI / 2, 3, 3);

    g2.drawImage(sprite, xform, null);
  }
  public void drawProjectile(Graphics2D g2d) {

    AffineTransform trans = new AffineTransform();
    trans.rotate(rotation, x, y);
    trans.translate(15, 0);
    g2d.setTransform(trans);

    g2d.drawImage(texture, (int) (x) + 5, (int) (y) - sY / 2, (int) sX, sY, null);
  }
예제 #27
0
파일: IconIO.java 프로젝트: munix/jdget
  /**
   * @param drop
   * @param i
   * @return
   */
  public static BufferedImage rotate(final BufferedImage src, final int degree) {
    final int w = src.getWidth(null);
    final int h = src.getHeight(null);

    // final Graphics2D g = image.createGraphics();
    // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    // RenderingHints.VALUE_ANTIALIAS_ON);

    final AffineTransform at = new AffineTransform();
    at.rotate(degree * Math.PI / 180.0);
    Point2D p2din, p2dout;

    p2din = new Point2D.Double(0.0, 0.0);
    p2dout = at.transform(p2din, null);
    double ytrans = p2dout.getY();
    double xtrans = p2dout.getX();
    p2din = new Point2D.Double(0, h);
    p2dout = at.transform(p2din, null);
    ytrans = Math.min(ytrans, p2dout.getY());
    xtrans = Math.min(xtrans, p2dout.getX());
    p2din = new Point2D.Double(w, h);
    p2dout = at.transform(p2din, null);
    ytrans = Math.min(ytrans, p2dout.getY());
    xtrans = Math.min(xtrans, p2dout.getX());
    p2din = new Point2D.Double(w, 0);
    p2dout = at.transform(p2din, null);
    ytrans = Math.min(ytrans, p2dout.getY());
    xtrans = Math.min(xtrans, p2dout.getX());

    final AffineTransform tat = new AffineTransform();
    tat.translate(-xtrans, -ytrans);

    at.preConcatenate(tat);
    final AffineTransformOp bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

    final Rectangle r = bio.getBounds2D(src).getBounds();

    BufferedImage image = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB);

    image = bio.filter(src, image);
    // final Graphics g = image.getGraphics();
    // g.setColor(Color.RED);
    // g.drawRect(0, 0, image.getWidth() - 1, image.getHeight() - 1);
    // g.dispose();
    // try {
    // Dialog.getInstance().showConfirmDialog(0, "", "", new
    // ImageIcon(image), null, null);
    // } catch (final DialogClosedException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // } catch (final DialogCanceledException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    return image;
  }
예제 #28
0
 // Function to rotate spaceship using direction (left/right)
 public void rotate(int direction) {
   rotateAngle += direction * ANGLE;
   rotateAngle = rotateAngle % 360;
   double locationX = imageWidth / 2;
   double locationY = imageHeight / 2;
   this.angle = Math.toRadians(rotateAngle);
   tx.rotate(angle);
   tx = AffineTransform.getRotateInstance(angle, locationX, locationY);
   op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
 }
예제 #29
0
 /**
  * Rotate the current transform over the Z-axis. Calls writeTransform(Transform). Rotating with a
  * positive angle theta rotates points on the positive x axis toward the positive y axis.
  *
  * @param theta radians over which to rotate
  */
 public void rotate(double theta) {
   currentTransform.rotate(theta);
   try {
     writeTransform(
         new AffineTransform(
             Math.cos(theta), Math.sin(theta), -Math.sin(theta), Math.cos(theta), 0, 0));
   } catch (IOException e) {
     handleException(e);
   }
 }
예제 #30
0
 protected AffineTransform getArrowTrans(
     double sx, double sy, double ex, double ey, double width, double theta) {
   m_arrowTrans.setToTranslation(ex, ey);
   m_arrowTrans.rotate(-HALF_PI + theta + Math.atan2(ey - sy, ex - sx));
   if (width > m_width) {
     double scalar = width / 3;
     m_arrowTrans.scale(scalar, scalar);
   }
   return m_arrowTrans;
 }