Java, i need help with a recursion base case please
I'm writing a program that prints Sierpinski's Carpet in a recursive method. I just need to figure out a base case for this method. And one more thing the picture is supposed to have more dots(small squares) in between the squares that don't seem to show in my method. any suggestions are welcomed.
Code:
import java.awt.*;
public class Sierpinski{
public static void main(String args[])
{
DrawingPanel panel = new DrawingPanel(242,242);
Graphics g = panel.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0,0,242,242);
drawGasket(g,0, 0, 243);
}
public static void drawGasket(Graphics g,int x, int y, int side) {
int temp= side/3;
g.setColor(Color.BLACK);
g.fillRect(x + temp, y + temp, temp - 1, temp - 1);
if(temp>=3)
{
drawGasket(g,x,y,temp);
drawGasket(g,x+temp,y,temp);
drawGasket(g,x+2*temp,y,temp);
drawGasket(g,x,y+temp,temp);
drawGasket(g,x+2*temp,y+temp,temp);
drawGasket(g,x,y+2*temp,temp);
drawGasket(g,x+temp,y+2*temp,temp);
drawGasket(g,x+2*temp,y+2*temp,temp);
}
}
}