title: I'm trying to write a recursive java program to create the Serpinski triangle
body: <p>The issue I'm having is that the output png only shows recursion on the bottom left corner, and I cant figure out why. Could someone please point me in the right direction, and Sorry about the messy comments. 
  Thank you.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics2D;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  import javax.imageio.ImageIO;
  
  public class Assignment12 {
  static int WIDTH = 0;
  static int HEIGHT = 0;
  static ArrayList&lt;Double&gt; points = new ArrayList&lt;Double&gt;();
  
  public static void main(String[] args) {
      if (args.length == 0) {
          WIDTH = 800;
          HEIGHT = 693;
      } else {
          Integer W = Integer.valueOf(args[0]);
          Integer H = Integer.valueOf(args[0]);
          WIDTH = W;
          HEIGHT = H;
      }
      // DONE //*********stuff to do ***********create the final ordered pairs
      // of the biggest triangle
      // done// *********stuff to do *********** set the values of the ordered
      // pairs
      // to the dimensions of the rectangle
      final double topX = WIDTH / 2;
      final double topY = 0;
      final double leftX = 0;
      final double leftY = HEIGHT - 1;
      final double rightX = WIDTH - 1;
      final double rightY = HEIGHT - 1;
      sierpinski(topX, topY, leftX, leftY, rightX, rightY);
      // ##############jeffs code#########
      // BufferedImage creates memory space for storing image data
      BufferedImage img = new BufferedImage(WIDTH, HEIGHT,
              BufferedImage.TYPE_INT_RGB);
      // Graphics2D provides a canvas on which to draw shapes, text, other
      // images
      Graphics2D g2d = img.createGraphics();
      // *********stuff to do *********** do the back ground stuffs
      // Clear background to white
      g2d.setColor(Color.white);
      g2d.fillRect(0, 0, WIDTH, HEIGHT);
      // start drawing lines in the correct color.
      // Red line from where to where?
      g2d.setColor(Color.red);
      for (int i = 0; i &lt; points.size(); i = i + 4) {
          g2d.drawLine(points.get(i).intValue(),
                  points.get(i + 1).intValue(), points.get(i + 2).intValue(),
                  points.get(i + 3).intValue());
      }
      // g2d.drawLine(0, 0, WIDTH - 1, HEIGHT - 1);
      // done// *********stuff to do *********** initialize the recursive
      // function to
      // done// *********stuff to do *********** get rid of these oval things
      // there
      // just for reference,
      // Draw some random ovals
      // for (int i = 0; i &lt; 100; i++) {
      // g2d.setColor(new Color((float) Math.random(),
      // (float) Math.random(), (float) Math.random()));
      // g2d.fillOval((int) (Math.random() * WIDTH),
      // (int) (Math.random() * HEIGHT), (int) (Math.random() * 50),
      // (int) (Math.random() * 50));
      // }
      // Finalize the canvas
      g2d.dispose();
      // Write the image out as a PNG-format file
      try {
          ImageIO.write(img, "png", new File("out.png"));
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  // *********stuff to do *********** create the recursive function for the
  // triangles
  private static void sierpinski(double topX, double topY, double leftX,
          double leftY, double rightX, double rightY) {
      // base case area of the triangle reaches x
      // (Ax(By-Cy)+Bx(Cy-Ay)+Cx(Ay-By))/2
      if (((leftX * (topY - rightY)) + (topX * (rightY - leftY)) + (rightX * (leftY - topY)) / 2) &gt; 10) {// &lt;--
          // that 10 should be a static value or just pulled directly from
          // args
          // start recursive for all three respective points
          double leftMidX = (topX + leftX) / 2;
          double leftMidY = (topY + leftY) / 2;
          double rightMidX = (topX + rightX) / 2;
          double rightMidY = (topY + rightY) / 2;
          // ***these are just called topMid for convenience. they are the mid
          // point values to the bottom line of the triangle.
          double botMidX = (leftX + rightX) / 2;
          double botMidY = (leftY + rightY) / 2;
          // top ... top stays the same
          sierpinski(topX, topY, leftMidX, leftMidY, rightMidX, rightMidY);
          // left
          sierpinski(leftMidX, leftMidY, leftX, leftY, botMidX, botMidY);
          // right
          sierpinski(rightMidX, rightMidY, botMidX, botMidY, rightX, rightY);
      } else {
          points.add(topX);
          points.add(topY);
          points.add(rightX);
          points.add(rightY);
          points.add(topX);
          points.add(topY);
          points.add(leftX);
          points.add(leftY);
          points.add(leftX);
          points.add(leftY);
          points.add(rightX);
          points.add(rightY);
          // draw the lines
          // g2d.drawLine(topX, topY, rightX, rightY);// right
          // g2d.drawLine(topX, topY, leftX, leftY);// left
          // g2d.drawLine(leftX, leftY, rightX, rightY);// bot
      }
  }
  </code></pre>
  
  <p>}</p>