title: Java- Creating a discrete rainbow colour array
body: <p>Hard to describe what I'm trying to do. I basically want to create a discrete rainbow gradient so that for any line of i number of JButtons, the colour gradient across them will look rainbow.</p>
  
  <p>I have done the following but it only really creates a red gradient followed by green gradient followed by blue gradient:</p>
  
  <pre><code>Color[] c = new Color[i];
      for(int n = 0; n &lt; i; n++) {
          if(n &lt; i/3) {
              c[n] = new Color(255, 255/(n+1), 255/(n+1));
          } else if(n &lt; 2*i/3) {
              c[n] = new Color(255/(n-(i/3)), 255, 255/(n-(i/3)));
          } else {
              c[n] = new Color(255/(n+1), 255/(n+1), 255);
          }
      }
  </code></pre>
  
  <p>Any Idea how I would be able to get some type of rainbow effect?</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>Used a Sine function which seems to work slightly better, but not sure how to define it so I get one "rainbow wave" in the region I want:</p>
  
  <pre><code>for(int n = 0; n &lt; i; n++) {
          c[n] = new Color((int)(Math.sin(n) * 127 + 128), (int)(Math.sin(n + Math.PI/2) * 127 + 128), (int)(Math.sin(n + Math.PI) * 127 + 128));
      }
  </code></pre>