title: Rotating Java 2D Graphics Around Specified Point
body: <p>I'm trying to write a program that will draw several shapes rotated around a center point.  The result should be something like a Spirograph.  I'm trying to test it using rectangles but I can only get two of them to appear in the window.  One of them is where it should be, but then after the first rotation it throws the other square way up in the top left corner of the window.  It should be rotated and drawn around the center point.  Here is a portion of my code.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.geom.Ellipse2D;
  
  import javax.swing.JPanel;
  
  public class Shapes extends JPanel
  {
  private double angle;
  private int type;
  private int radius;
  private int repeats;
  
  public Shapes(int t, int r, int z)
  {
     type = t;
     radius = r;
     repeats = z;      
     angle = 360 / repeats;
  }
  
  public void paintComponent( Graphics g )
  {
    super.paintComponent( g );
    Graphics2D g2d = (Graphics2D)g;
  
    g.setColor(Color.red);
  
    int centerX = getWidth()/2;
    int centerY = getHeight()/2;
  
    double curAngle = 0;
  
    for(int i=0; i&lt;=repeats; i+=1)
    {
        g.setColor(Color.blue);
  
        Rectangle tangle = new Rectangle(0, 0, radius, radius);
        g2d.rotate(Math.toRadians(curAngle));
        g2d.translate(centerX, centerY);
        g2d.draw(tangle);
        curAngle += angle;
    }
  </code></pre>
  
  <p>}</p>