Created
November 24, 2011 22:25
-
-
Save nicolaiarocci/1392432 to your computer and use it in GitHub Desktop.
A very simple and partial implementation of the Koch Curve in Python (part of a school project)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
# alza la penna dal foglio | |
# (necessario perché per default è abbassata e traccerebbe una linea | |
# nel corso della setpos successiva) | |
turtle.up() | |
# imposta posizione iniziale della penna | |
# (0,0 è il centro del foglio) | |
turtle.setpos(-200, 0) | |
iterazione = 3 | |
movimento ="F" | |
# lunghezza del tratto iniziale | |
distanza = 40 | |
for i in range(iterazione): | |
movimento = movimento.replace("F","FLFRFLF") | |
turtle.down() | |
for move in movimento: | |
if move is "F": | |
turtle.forward(distanza / 3**i) | |
if move is "L": | |
turtle.left(60) | |
if move is "R": | |
turtle.right(120) | |
if i <2: | |
# premi un tasto prima della iterazone successiva | |
# il test evita l'input alla fine dell'ultima iterazione (i=2) | |
raw_input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment