From 5085cc104adb35ea59cb68ec9a0b745bc4c3ceff Mon Sep 17 00:00:00 2001 From: autoscatto Date: Fri, 10 Jun 2016 18:42:14 +0200 Subject: [PATCH] knotta! --- knot.py | 35 +++++++++++++++++++++++++++++++++++ knotta.py | 5 +++++ 2 files changed, 40 insertions(+) create mode 100644 knot.py create mode 100644 knotta.py diff --git a/knot.py b/knot.py new file mode 100644 index 0000000..245ed79 --- /dev/null +++ b/knot.py @@ -0,0 +1,35 @@ + +class K(object): + def __init__(self, s="FLFRFLFRFLFRFLFRFLFRFLF", i=1): + self.kf = s + self.i = i + + def __xor__(self, o): + return K(self.kf.replace("F", "FLFRFLF"), self.i+1) + + def __nonzero__(self): + import turtle + k_ = turtle.Turtle() + turtle.resetscreen() + turtle.title("Iteration: %d" % self.i) + k_.ht() + turtle.setup(400, 400) + k_.down() + k_.speed('fastest') + k_.penup() + k_.goto(-150, 100) + k_.pendown() + for move in self.kf: + if move == "F": + k_.forward(100.0 / (3 ** (self.i - 1))) + elif move == "L": + k_.left(60) + elif move == "R": + k_.right(120) + + return 0 + + +k = K() + + diff --git a/knotta.py b/knotta.py new file mode 100644 index 0000000..2bcc324 --- /dev/null +++ b/knotta.py @@ -0,0 +1,5 @@ +from knoth import k +not k ^ k +#not k ^ k ^ k +import turtle; turtle.done() +