I cannot get this koch snowflake drawing working recursively.
Recursive method
public void koch(int n, double size) {
if (n == 0) {
t.forward(size);
} else {
koch(n - 1, size / 3); // line 1
stdTort.rotate(60); // line 2
koch(n - 1, size/3); // line 3
stdTort.rotate(120); // line 4
koch(n - 1, size/3); // line 5
stdTort.rotate(60); // line 6
koch(n - 1, size/3); // line 7
}
}
Any help would be appreciated.
All of your angles are wrong, because they are rotating clockwise where you are expecting them to go anti-clockwise. In order to get the angle shown in figure 2 you actually need to rotate 120, not 60. Then to get your final line you want to rotate -60, not 60.
Thinking about this, I think the reason you are confused is because the rotation doesn’t seem to be intuitive. If your turtle is walking forward to do the first line, then you would expect a rotation to be either clockwise or anti-clockwise from that direction. But it seems your rotation all starts from the opposite direction.
Expected:
Actual: