I have two questions regarding AffineTransforms. First, how do I change the radius of rotation so that my leaf (see code) rotes on a dime rather than over a big radius. A rotation of 45 degrees moves the leaf practically to the bottom of the screen and although it does rotate, this is not the result I'm looking for (I'm trying to get a leaf blowing in the wind effect here).
Also, after I rotate the leaf, how do I recolor it. Only the edges are coming out green, the inside is coming out white.
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import javax.swing.JFrame;
public class MovingLeaf extends JFrame {
public static void main(String[] args) {
new MovingLeaf();
}
public MovingLeaf() {
super("Beach");
setSize(600, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
GeneralPath leaf = new GeneralPath();
leaf.moveTo(300,100);
leaf.quadTo(400,100,400,200);
leaf.lineTo(380,180);
leaf.lineTo(380,160);
leaf.lineTo(360,170);
leaf.lineTo(365,150);
leaf.lineTo(335,155);
leaf.lineTo(340,135);
leaf.lineTo(320,140);
leaf.lineTo(320,120);
leaf.lineTo(305,125);
leaf.lineTo(300,100);
leaf.closePath();
g2d.setColor(Color.green);
g2d.fill(leaf);
AffineTransform rotation = new AffineTransform();
rotation.setToRotation(Math.toRadians(45));
g2d.fill(leaf);
g2d.draw(rotation.createTransformedShape(leaf));
}
}