Every call to createCircles()
should paint one large circle in the center and call itself recursively 3 times for the 3 smaller circles. The y
coordinate always remains the same and you can recalculate the x
coordinate by adding and subtracting the radius of original circle.
public void createCircles(int x, int y, int rad) {
Circle myCircle = new Circle(x, y, rad);
circles.add(myCircle);
createCircles(x - (2*rad), y, rad/3);
createCircles(x, y, rad/3);
createCircles(x + (2*rad), y, rad/3);
}
For the overflow error you can set a terminating condition on the size of rad
, like
if (rad < 5) {
return;
}