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
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.
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.
posted 10 years ago
I found out my problems and properly fixed my base case (correctly this time).
I was born with webbed fish toes. This tiny ad is my only friend:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database