title: Nesting parabolic curves from straight lines
body: <p>I am having trouble replicating the picture for my assignment. I would appreciate any tips or solutions. I believe I have the general idea down, but I am having a hard time figuring out the math to replicate the image and doing everything in a single loop.</p>
  
  <p>My program needs to meet these criteria:</p>
  
  <ol>
  <li>Match the Image</li>
  <li>Generate a random color for each pair of parabolic curve</li>
  <li>Work with any width or height </li>
  <li>Use a single loop to draw the entire figure.</li>
  </ol>
  
  <p>Here is the image:
  <img src="https://i.stack.imgur.com/6UJPi.png" alt="Image">
  This is what I have tried so far</p>
  
  <pre><code>public static final int WIDTH = 500;
  public static final int HEIGHT = 500;
  public static final int LINE_INCREMENT = 5;
  
  public static void main(String[] args) {
  
      DrawingPanel panel = new DrawingPanel(WIDTH, HEIGHT);
      Graphics g = panel.getGraphics();
      int d = 0;
  
      int iterations = HEIGHT/LINE_INCREMENT;
      Random rand = new Random();
      int red = 0, green = 0, blue = 0;
      red = rand.nextInt(128) + 128;
      green = rand.nextInt(128) + 128;
      blue = rand.nextInt(128) + 128;
      g.setColor(new Color(red,green,blue));
  
          for(int y = 0; y &lt; iterations; y++) {
              g.drawLine(0, d, d, HEIGHT);
              g.drawLine(WIDTH, d, d, 0);
  
              d += LINE_INCREMENT;
          }
  
          red = rand.nextInt(128) + 128;
          green = rand.nextInt(128) + 128;
          blue = rand.nextInt(128) + 128;
          g.setColor(new Color(red,green,blue));
          d = 0;
  
          for (int x = 0; x &lt; iterations/2; x++) {
              g.drawLine(WIDTH/4, d + HEIGHT/4, d + WIDTH/4, HEIGHT - HEIGHT/4);
              g.drawLine(d + WIDTH/4, WIDTH/4, WIDTH - WIDTH/4, d + WIDTH/4);
  
              d += LINE_INCREMENT;
  
          }           
  }
  </code></pre>
  
  <p>The output:</p>
  
  <p><a href="https://i.stack.imgur.com/dTHBX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dTHBX.png" alt="Result"></a></p>