java - Rotating rectangle and adjust positon -
java - Rotating rectangle and adjust positon -
i'm struggling rotation of rectangles. have rectangle consists of 9 little rectangles. http://i57.tinypic.com/msn8ue.jpg
now rotated big rectangle accordingly affine transformation, worked pretty fine. http://i61.tinypic.com/25phlqp.jpg
my problem need move rectangles, top left position of each rectangle @ point x,y.
i don't know how , hope can help me out.
thanks!
public class mainclass { public static void main(string[] args) { jframe jf = new jframe("demo"); container cp = jf.getcontentpane(); mycanvas tl = new mycanvas(); cp.add(tl); jf.setsize(800, 800); jf.setvisible(true); } } class mycanvas extends jcomponent { private static final long serialversionuid = 5703217428905757134l; @override public void paint(graphics g) { graphics2d g2 = (graphics2d) g; g2.setrenderinghint(renderinghints.key_antialiasing, renderinghints.value_antialias_on); int x = 400; int y = 400; int width = 100; int height = 200; final int overlapping_outline = 10; rectangle[] rect = new rectangle[9]; rect[0] = new rectangle(x + overlapping_outline, y + overlapping_outline, width - 2 * overlapping_outline, height - 2 * overlapping_outline); rect[1] = new rectangle(x - overlapping_outline, y - overlapping_outline, overlapping_outline * 2, overlapping_outline * 2); rect[2] = new rectangle(x - overlapping_outline + width, y - overlapping_outline, overlapping_outline * 2, overlapping_outline * 2); rect[3] = new rectangle(x - overlapping_outline, y + height - overlapping_outline, overlapping_outline * 2, overlapping_outline * 2); rect[4] = new rectangle(x - overlapping_outline + width, y + height - overlapping_outline, overlapping_outline * 2, overlapping_outline * 2); rect[5] = new rectangle(x - overlapping_outline, y + overlapping_outline, overlapping_outline * 2, height - overlapping_outline * 2); rect[6] = new rectangle(x - overlapping_outline + width, y + overlapping_outline, overlapping_outline * 2, height - overlapping_outline * 2); rect[7] = new rectangle(x + overlapping_outline, y - overlapping_outline, width - overlapping_outline * 2, 2 * overlapping_outline); rect[8] = new rectangle(x + overlapping_outline, y + height - overlapping_outline, width - overlapping_outline * 2, 2 * overlapping_outline); (rectangle r : rect) g2.draw(r); g2.setcolor(color.red); affinetransform af = new affinetransform(); (int = 90; < 360; += 90) { af.rotate(math.toradians(i), x - overlapping_outline, y - overlapping_outline); (rectangle r : rect) { shape shape = af.createtransformedshape(r); g2.draw(shape); } } } }
it looks need utilize affinetransform.translate(double tx, double ty)
.
java rotation affinetransform translate-animation
Comments
Post a Comment