title: How to use index to derive pseudorandom gradient in 2D simplex noise
body: <p>When using simplex noise one of it's main features is in the generation of gradients on-the-fly. This algorithm is described <a href="https://www.csee.umbc.edu/~olano/s2002c36/ch02.pdf" rel="nofollow noreferrer">here</a>. The problem is that even in the <a href="https://www.google.com/patents/US6867776" rel="nofollow noreferrer">patent</a> the gradient generation algorithm is only described in three dimensions (see below).</p>
  
  <p><em>The specific new technique is as follows: The six bit index is split into (i) a lower three bit quantity, which is used to compute a magnitude of either zero or one for each of x,y and z, and (ii) an upper three bit quantity, which is used to determine an octant for the resulting gradient (positive or negative sign in each of x,y, and z).</em></p>
  
  <p><em>If bit1bit0=0, then let (p,q,r)=(x,y,z). Otherwise, let (p,q,r) be a rotation of the order of (x,y,z) to (y,z,x) or (z,x,y), as bit1bit0=1 or 2, respectively, and set either q or r to zero as bit2=0 or 1, respectively.</em></p>
  
  <p>000 p = x q = y r = z<br>
  001 p = y q = z r = 0<br>
  010 p = z q = x r = 0<br>
  011 p = x q = y r = 0<br>
  100 p = x q = y r = z<br>
  101 p = y q = 0 r = x<br>
  110 p = z q = 0 r = y<br>
  111 p = x q = 0 r = z</p>
  
  <p>Then you basically continue and flip the signs of the components of the generated gradient.</p>
  
  <p>The problem is basically how does the above rotation algorithm translate to 2D?</p>