Your code is drawing 11 circles but your call(s) to the drawRCircles
itself is responsible for only 10 of them.
More specifically, these lines are drawing 1 circle.
// draw main circle
graphics.setColor(Color.WHITE);
graphics.drawOval(xOrigin, yOrigin, n, n);
This circle gets drawn regardless of whether or not you even have a drawRCircles
function. (Try removing it and running your code to see what happens.)
Then, your code calls the drawRCircles
function 11 times, but only draws 10 circles since the last call to it, with level = 0 fails the test if(level > 0)
.
the Image it creates goes down so far that I can not count the circles :/
A quick tip: since you want to know if, given max level of N
, will it draw N
or N+1
levels of circles, you could also just try changing your level
variable to something more manageable (like 2) and checking it visually.
Going back to your code above, and ignoring the draw main circle
portion (since it's independent of your recursive circle drawing) you have
drawRCircles(graphics,xOrigin,yOrigin,radius,level); // call recursive method
System.out.println(level);
and within your public void drawRCircles(…)
function,
drawRCircles(…,level-1);
Let's check it with level = 2 instead of 10:
drawRCircles(…, 2)
--> Check if 1 > 0.
--> Yes, 1 > 0 so drawRCircles(…, 1)
--> Check if 0 > 0.
--> No, 0 = 0, so stop.
Number of levels = 2 = number of recursive circles drawn.