Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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:
• Campbell Ritchie
• Jeanne Boyarsky
• Bear Bibeault
• Knute Snortum
• Liutauras Vilda
Sheriffs:
• Tim Cooke
• Devaka Cooray
• Paul Clapham
Saloon Keepers:
• Tim Moores
• Frits Walraven
• Ron McLeod
• Ganesh Patekar
• salvin francis
Bartenders:
• Tim Holloway
• Carey Brown
• Stephan van Hulst

# 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
Posts: 39054
714
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

 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 https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database