[Help] Koch snowflake from Python 2.5 [Turtle]

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2009
Posts: 2
Reputation: Oldguy1 is an unknown quantity at this point 
Solved Threads: 0
Oldguy1 Oldguy1 is offline Offline
Newbie Poster

[Help] Koch snowflake from Python 2.5 [Turtle]

 
0
  #1
Sep 28th, 2009
Hey I'm very new to the programming world, and what i am trying to do is produce a Koch Snowflake via turtle from python2.5.
this is what I have so far...
  1. from turtle import *
  2.  
  3. def snowflake(lengthSide, levels):
  4. if levels == 0:
  5. return forward(lengthSide), right(120), forward(lengthSide), right(120), forward(lengthSide)
  6.  
  7. forward(lengthSide)
  8. left(60)
  9. forward(lengthSide)
  10. right(60)
  11. right(60)
  12. forward(lengthSide)
  13. left(60)
  14. forward(lengthSide)
  15. right(120)
  16. snowflake(lengthSide, levels)
as you can see i've only solved for levels 0 and 1... the problem is i dont understand how to recursively redraw it from a certain location. If anyone has any ideas or tip, it would be helpful.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 960
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 220
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: [Help] Koch snowflake from Python 2.5 [Turtle]

 
0
  #2
Sep 28th, 2009
I suggest this
  1. from turtle import *
  2.  
  3. def snowflake(lengthSide, levels):
  4. if levels == 0:
  5. forward(lengthSide)
  6. return
  7. lengthSide /= 3.0
  8. snowflake(lengthSide, levels-1)
  9. left(60)
  10. snowflake(lengthSide, levels-1)
  11. right(120)
  12. snowflake(lengthSide, levels-1)
  13. left(60)
  14. snowflake(lengthSide, levels-1)
  15.  
  16.  
  17. if __name__ == "__main__":
  18. speed(0)
  19. length = 300.0
  20. penup()
  21. backward(length/2.0)
  22. pendown()
  23. snowflake(length, 4)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 2
Reputation: Oldguy1 is an unknown quantity at this point 
Solved Threads: 0
Oldguy1 Oldguy1 is offline Offline
Newbie Poster

Re: [Help] Koch snowflake from Python 2.5 [Turtle]

 
0
  #3
Sep 28th, 2009
Thank you very much, this helped alot!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC