title: How to draw and rotate square inside center of other square?
body: <p>I need to draw some squares inside other square but I don't know how to rotate my squares by center of them and make them smaller? 
  Here is a picture how it should looks like at the end: </p>
  
  <p><img src="https://i.stack.imgur.com/DRl0m.jpg" alt="enter image description here"></p>
  
  <p>Now I have some code which draw squares which make circle.</p>
  
  <pre><code>class MySquare  extends JComponent {
  public void paint(Graphics g) {
  
      Graphics2D g2d = (Graphics2D) g;
      for (int i = 0; i &lt; 20; i++) {
  
          g2d = (Graphics2D) g.create();
          g2d.rotate(Math.toRadians(45 - (i * 10)), 100, 100);
  
          // Difrent colors:
          if (i % 2 == 0)
              g2d.setColor(Color.black);
          else
              g2d.setColor(Color.green);
          g2d.fillRect(50, 50, 100, 100);
  
      }
      }
  }
  
  public class DrawRect {
    public static void main(String[] a) {
      JFrame window = new JFrame();
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      window.setBounds(30, 30, 800, 800);
      window.getContentPane().add(new MySquare());
      window.setVisible(true);
    }
  }
  </code></pre>