-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathturtle_hilbert.py
49 lines (43 loc) · 1.05 KB
/
turtle_hilbert.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
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import board
from adafruit_turtle import turtle
def hilbert2(step, rule, angle, depth, t):
if depth > 0:
a = lambda: hilbert2(step, "a", angle, depth - 1, t)
b = lambda: hilbert2(step, "b", angle, depth - 1, t)
left = lambda: t.left(angle)
right = lambda: t.right(angle)
forward = lambda: t.forward(step)
if rule == "a":
left()
b()
forward()
right()
a()
forward()
a()
right()
forward()
b()
left()
if rule == "b":
right()
a()
forward()
left()
b()
forward()
b()
left()
forward()
a()
right()
turtle = turtle(board.DISPLAY)
turtle.penup()
turtle.setheading(90)
turtle.goto(-80, -80)
turtle.pendown()
hilbert2(5, "a", 90, 5, turtle)
while True:
pass