title: Simple circle rotation (simulate motion)
body: <p>I have a simple animation in Java that consists of a wheel moving across a window. It is just a plain circle that starts off of the screen from the left, enters and continues to the right until it goes off of the screen. Then it loops and repeats this process.</p>
  
  <p><code>X</code> is a variable that contains the position of the wheel. It can be between -(wheel width) and the window size + the wheel width. </p>
  
  <p>I would like to simulate rotation by drawing a circle within this wheel, that rotates around the circle as if it were attached.</p>
  
  <p>Imagine a bike wheel in real life with a red flag on the wheel. As the wheel rotates, the red flag would be on the edge on the wheel moving as the wheel progresses. This is the behavior I want.</p>
  
  <p>I am getting a percentage to pass into my wheel class like this:</p>
  
  <pre><code>int percentage = x/windowWidth;
  </code></pre>
  
  <p>Each frame that the wheel moves, I call <code>wheel.rotate(percentage)</code>. </p>
  
  <p>This is the implementation:</p>
  
  <pre><code>private int diameter = 50;        
  private final int SPOKE_DIAMETER = diameter/5;
  
      public void rotate(double percent){
          this.percent = percent;
          this.theta = percent*(PI*2);
          System.out.println(percent*PI);
      }
  
      public void paintComponent(Graphics canvas)
      {
          // wheel
          canvas.setColor(Color.gray);
          canvas.fillOval(0, 0, diameter, diameter);
  
          // spinning flag
          canvas.setColor(Color.red);
          canvas.fillOval((int)(percent*diameter),(int)((sin((percent*(PI*2)))*diameter)), SPOKE_DIAMETER,SPOKE_DIAMETER);
      }
  </code></pre>
  
  <p>The x location works more or less how I wanted, but the y does not. It wiggles like a sin wave, which is expected (I <em>did</em> use sin...), however, I'm not sure how to alter my math to follow the circle around. </p>
  
  <p>What is wrong with my implementation? (I'm not very good with drawing with trigonometric functions)</p>