title: Rotating an image with the mouse
body: <p>I am writing a drawing program, Whyteboard -- <a href="http://code.google.com/p/whyteboard/" rel="nofollow noreferrer">http://code.google.com/p/whyteboard/</a></p>
  
  <p>I have implemented image rotating functionality, except that its behaviour is a little odd. I can't figure out the proper logic to make rotating the image in relation to the mouse position</p>
  
  <p>My code is something similar to this:</p>
  
  <p>(these are called from a mouse event handler)</p>
  
  <pre><code>def resize(self, x, y, direction=None):
      """Rotate the image"""
      self.angle += 1
      if self.angle &gt; 360:
          self.angle = 0
      self.rotate()
  
  
  def rotate(self, angle=None):
      """Rotate the image (in radians), turn it back into a bitmap"""
      rad = (2 * math.pi * self.angle) / 360
      if angle:
          rad = (2 * math.pi * angle) / 360
      img = self.img.Rotate(rad, (0, 0))
  </code></pre>
  
  <p>So, basically the angle to rotate the image keeps getting increased when the user moves the mouse. However, this sometimes means you have to "circle" the mouse many times to rotate an image 90 degrees, let alone 360. </p>
  
  <p>But, I need it similar to other programs - how the image is rotated in relation to your mouse's position to the image.</p>
  
  <p>This is the bit I'm having trouble with. I've left the question language-independent, although using Python and wxPython it could be applicable to any language</p>