Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Koch Curve

Ranch Hand
Posts: 33
Not sure if I should post this in the beginner's section but here it goes. I thought this "Koch Curve" would be fun because it looks cool. The problem I'm having is that it is stuck on the first iteration and it won't draw more of those triangles. This is the code I have so far that runs:

I'm having a feeling that I'm missing a parameter for the recursion part of it since it is basically redrawing the same starting triangle over again.
Thanks

author & internet detective
Sheriff
Posts: 38035
605
Justin,
In recursion, there is always a "base case" and a recursive case that should bring you one step closer to the base case.

In your example, the base case is c != level. The recursive case makes level one smaller and c one bigger each time. Since c is starting out larger than level (c=3, level=0), how does the recursion end.

This forum (intermediate) is fine since your question is about recursion. That's too advanced for beginners. If it was about the graphics themselves, it would go in the applets forum.

Tom Cameron
Ranch Hand
Posts: 33
Thanks Jeanne for a fast reply. I think I fixed my base case now with this new code:

My main problem is that I can't get my program to draw the next "set of triangles" on the next "level", i.e. 2 smaller triangles on the bigger triangle and 1 triangle on each end of the line ( a total of 5 triangles). instead, I'm stuck with 1 triangle the whole time, so I figure I'm doing my recursion wrong somehow.

Tom Cameron
Ranch Hand
Posts: 33
I found out my problems and properly fixed my base case (correctly this time).

Thanks anyways