I'm somewhat new to java graphics and am trying to learn how to use rotation. from what I have read 'affineTransform' is the key to pretty much all of it. Here I can't seem to figure out how I would create this rectangle and apply rotation to it. any ideas?
package games;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Rotation extends JPanel {
public static void main(String[] args) {
JFrame f = new JFrame();
f.add(new Rotation());
f.setSize(600, 600);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
int i = 0;
public void paint(Graphics g) {
Rectangle ship = new Rectangle(50, 50, 200, 100); // <------
AffineTransform at = new AffineTransform();
at.rotate(Math.toRadians(i++), ship.getWidth() / 2, ship.getHeight() / 2);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(ship, at, null); // <----------------
repaint();
}
}