-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragon.py
69 lines (57 loc) · 1.9 KB
/
dragon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
from cli_draw import Direction, Turn, draw
class Dragon:
def __init__(self, depth: int):
self.turns = []
self.trace(depth)
def trace(self, depth: int):
self.trace_depth(depth, Turn.R)
def trace_depth(self, n: int, turn: Turn):
if n > 0:
self.trace_depth(n - 1, Turn.R)
self.write(turn)
self.trace_depth(n - 1, Turn.L)
def write(self, turn: Turn):
self.turns.append(turn)
def main(depth: int = 5,
initial_direction: Direction = Direction.R,
x_step: int = 2,
y_step: int = 1,
turns_only: bool = False,
):
dragon = Dragon(depth)
if turns_only:
print(''.join(turn.name for turn in dragon.turns))
else:
draw(initial_direction, dragon.turns, x_step, y_step)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Draw a dragon curve.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("DEPTH", type=int, help="Depth of the dragon curve to generate")
parser.add_argument("--turns-only", action="store_true", help="Instead of drawing the curve, output the turns necessary for cli-draw to draw the curve")
parser.add_argument(
"--x-step",
"-x",
type=int,
default=2,
help="The number of columns a single x-axis step takes.",
)
parser.add_argument(
"--y-step",
"-y",
type=int,
default=1,
help="The number of lines a single y-axis step takes.",
)
parser.add_argument(
"--initial-direction",
"-d",
type=str,
default="R",
choices=Direction._member_names_,
help="The starting direction of travel.",
)
args = parser.parse_args()
main(args.DEPTH, Direction[args.initial_direction], args.x_step, args.y_step, args.turns_only)