List of usage examples for java.awt.geom AffineTransform getTranslateInstance
public static AffineTransform getTranslateInstance(double tx, double ty)
From source file:Main.java
public static BufferedImage getFlippedImage(BufferedImage bi) { BufferedImage flipped = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType()); AffineTransform tran = AffineTransform.getTranslateInstance(0, bi.getHeight()); AffineTransform flip = AffineTransform.getScaleInstance(1d, -1d); tran.concatenate(flip);//from w w w . ja v a 2 s . c o m Graphics2D g = flipped.createGraphics(); g.setTransform(tran); g.drawImage(bi, 0, 0, null); g.dispose(); return flipped; }
From source file:Main.java
static void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) { // x1 and y1 are coordinates of circle or rectangle // x2 and y2 are coordinates of circle or rectangle, to this point is directed the arrow Graphics2D g = (Graphics2D) g1.create(); double dx = x2 - x1; double dy = y2 - y1; double angle = Math.atan2(dy, dx); int len = (int) Math.sqrt(dx * dx + dy * dy); AffineTransform t = AffineTransform.getTranslateInstance(x1, y1); t.concatenate(AffineTransform.getRotateInstance(angle)); g.transform(t);/* w w w .j ava2 s . co m*/ g.drawLine(0, 0, len, 0); int basePosition = len - ARROW_HEAD_SIZE.width; int height = ARROW_HEAD_SIZE.height; g.fillPolygon(new int[] { len, basePosition, basePosition, len }, new int[] { 0, -height, height, 0 }, 4); }
From source file:RotateTransformed.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130); for (double i = 0; i < 360; i += 5) { AffineTransform at = AffineTransform.getTranslateInstance(400 / 2, 400 / 2); at.rotate(Math.toRadians(i)); g2.draw(at.createTransformedShape(e)); }//from www . j a va 2 s. c o m }
From source file:TextRendering.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Dimension d = getSize();/*from w ww.j a v a 2 s . c o m*/ AffineTransform ct = AffineTransform.getTranslateInstance(d.width / 2, d.height * 3 / 4); g2.transform(ct); String s = "www.java2s.com"; Font f = new Font("Serif", Font.PLAIN, 128); g2.setFont(f); int count = 6; for (int i = 1; i <= count; i++) { AffineTransform oldTransform = g2.getTransform(); float ratio = (float) i / (float) count; g2.transform(AffineTransform.getRotateInstance(Math.PI * (ratio - 1.0f))); float alpha = ((i == count) ? 1.0f : ratio / 3); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.drawString(s, 0, 0); g2.setTransform(oldTransform); } }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.black);//from w ww . ja v a2 s . c o m g2.draw(new Rectangle2D.Float(10, 20, 30, 40)); AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at); g2.setPaint(Color.red); g2.draw(new Rectangle2D.Float(10, 20, 30, 40)); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.black);/*from w w w .j av a 2 s. c om*/ g2.draw(new Rectangle2D.Float(10, 20, 30, 40)); AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.setTransform(at); g2.setPaint(Color.red); g2.draw(new Rectangle2D.Float(10, 20, 30, 40)); }
From source file:XORRectangles.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // using white as the XOR color. g2.setXORMode(Color.white);//from w ww .ja v a 2 s. c om // Paint a red rectangle. Rectangle2D r = new Rectangle2D.Double(50, 50, 150, 100); g2.setPaint(Color.red); g2.fill(r); g2.transform(AffineTransform.getTranslateInstance(25, 25)); // Draw a blue rectangle. g2.setPaint(Color.blue); g2.fill(r); }
From source file:Utils.java
public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius, boolean normalize) { Shape shape = generatePolygon(sides, outsideRadius, insideRadius); if (normalize) { Rectangle2D bounds = shape.getBounds2D(); GeneralPath path = new GeneralPath(shape); shape = path//from ww w . j ava 2s . c om .createTransformedShape(AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY())); } return shape; }
From source file:RotatedText.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "111111111111111111111111111111"; Font font = new Font("Courier", Font.PLAIN, 12); g2d.translate(20, 20);/*from ww w.j ava2 s . c o m*/ FontRenderContext frc = g2d.getFontRenderContext(); GlyphVector gv = font.createGlyphVector(frc, s); int length = gv.getNumGlyphs(); for (int i = 0; i < length; i++) { Point2D p = gv.getGlyphPosition(i); AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); at.rotate((double) i / (double) (length - 1) * Math.PI / 3); Shape glyph = gv.getGlyphOutline(i); Shape transformedGlyph = at.createTransformedShape(glyph); g2d.fill(transformedGlyph); } }
From source file:RollingText.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "Java Source and Support."; Font font = new Font("Serif", Font.PLAIN, 24); FontRenderContext frc = g2.getFontRenderContext(); g2.translate(40, 80);// ww w . ja v a 2 s. c o m GlyphVector gv = font.createGlyphVector(frc, s); int length = gv.getNumGlyphs(); for (int i = 0; i < length; i++) { Point2D p = gv.getGlyphPosition(i); double theta = (double) i / (double) (length - 1) * Math.PI / 4; AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); at.rotate(theta); Shape glyph = gv.getGlyphOutline(i); Shape transformedGlyph = at.createTransformedShape(glyph); g2.fill(transformedGlyph); } }