• Post Reply Bookmark Topic Watch Topic
  • New Topic
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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Koch Curve  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 38569
656
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out my problems and properly fixed my base case (correctly this time).

Thanks anyways
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!