title: Image rotation algorithm for a square pixel grid
body: <p>I'm currently working on my own little online pixel editor.<br>
  Now I'm trying to add a rotation function.
  But I can't quite figure out how to realize it.</p>
  
  <p>Here is the basic query for my pixel grid:</p>
  
  <pre><code>for (var y = 0;y &lt; pixelAmount;y++) {
      for (var x = 0;x &lt; pixelAmount;x++) {
          var name = y + "x" + x;
  
          newY = ?? ;
          newX = ?? ;
  
          if ($(newY + "x" + newX).style.backgroundColor != "rgb(255, 255, 255)")
          { $(name).style.backgroundColor = $(newY + "x" + newX).style.backgroundColor; }
      }
  }
  </code></pre>
  
  <p>How do I calculate <code>newY</code> and <code>newX</code>?</p>