Last active
December 16, 2015 20:39
-
-
Save georgyangelov/5494387 to your computer and use it in GitHub Desktop.
Visualizer for the dragon fractal challenge
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 | |
from solution import dragon_fractal | |
LINE_LENGTH = 5 # 1 | |
DELAY_MS = 0 | |
REPEAT_TIMES = 11 # 15 | |
def str_to_heading(str_): | |
if str_ == 'up': | |
return 90 | |
elif str_ == 'left': | |
return 180 | |
elif str_ == 'right': | |
return 0 | |
elif str_ == 'down': | |
return 270 | |
else: | |
raise Exception('Unknown heading {}'.format(str_)) | |
turtle.hideturtle() | |
turtle.speed(0) | |
turtle.delay(DELAY_MS) | |
dragon_iterator = iter(dragon_fractal()) | |
for _ in range(2 ** REPEAT_TIMES): | |
step_direction = next(dragon_iterator) | |
turtle.setheading(str_to_heading(step_direction)) | |
turtle.forward(LINE_LENGTH) | |
turtle.done() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment