I'm trying to make a Sierpinski Triangle using recursion and StdDraw, but I can't figure out how to make it work correctly. I know how to draw the triangles in the correct spots, but I can't make the recursion work in a way that it can draw the multiple triangles in one loop of the recursion. What I need to figure out is how to make that pattern in every subsequent triangle that is drawn as a result of the recursion.
public class Triangle { public static void drawTri(double x, double y, double s) { if (s<5 ) { return; } else { double[] a = {x,x+s/2,x+s}; double[] b = {y,y+s*Math.sqrt(3)/2,y}; StdDraw.polygon(a,b); double[] c = {x,x+s/4,x+s/2}; double[] d = {y,y+s*Math.sqrt(3)/4,y}; double[] e = {x+s/2,x+3*s/4,x+s}; double[] f = {y,y+s*Math.sqrt(3)/4,y}; double[] g = {x+s/4,x+s/2,x+3*s/4}; double[] h = {y+s*Math.sqrt(3)/4,y+s*Math.sqrt(3)/2,y+s*Math.sqrt(3)/4}; StdDraw.polygon(c,d); StdDraw.polygon(e,f); StdDraw.polygon(g,h); drawTri(x,y,s/2); } } public static void main(int size) { StdDraw.setXscale(0, size); StdDraw.setYscale(0, size); StdDraw.setPenColor(StdDraw.BLUE); drawTri(0, 0, size); } }