| | |
[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:
Solved Threads: 0
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...
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.
this is what I have so far...
Python Syntax (Toggle Plain Text)
from turtle import * def snowflake(lengthSide, levels): if levels == 0: return forward(lengthSide), right(120), forward(lengthSide), right(120), forward(lengthSide) forward(lengthSide) left(60) forward(lengthSide) right(60) right(60) forward(lengthSide) left(60) forward(lengthSide) right(120) snowflake(lengthSide, levels)
I suggest this
python Syntax (Toggle Plain Text)
from turtle import * def snowflake(lengthSide, levels): if levels == 0: forward(lengthSide) return lengthSide /= 3.0 snowflake(lengthSide, levels-1) left(60) snowflake(lengthSide, levels-1) right(120) snowflake(lengthSide, levels-1) left(60) snowflake(lengthSide, levels-1) if __name__ == "__main__": speed(0) length = 300.0 penup() backward(length/2.0) pendown() snowflake(length, 4)
![]() |
Similar Threads
- Python Turtle module, and math module problem. (Python)
- Koch Snowflake (Java)
- Koch Curve in Python (Python)
Other Threads in the Python Forum
- Previous Thread: Difference between cTurtle and turtle
- Next Thread: Need help with printing
| Thread Tools | Search this Thread |
ansi assignment avogadro backend beginner binary bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo wikipedia windows write wxpython xlib





