-
Notifications
You must be signed in to change notification settings - Fork 0
/
holes.py
66 lines (62 loc) · 1.78 KB
/
holes.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
from plot import Plot
from plot.utils import vec2, SQRT_2
import random
def main(p: Plot):
p.plot_size = 4
# p.options.speed_pendown = 50
p.setup()
p.draw_bounding_box(True)
lo = vec2(0, 0)
hi = vec2(1, 1)
layers = []
grid_size = 4
spacing = 7
scale = (100-spacing*(grid_size+1))/grid_size
inc = 0.2
min_space = p.inches_to_units(0.01)/scale
while lo.x < hi.x and lo.y < hi.y:
inc = max(inc - random.uniform(0.015, 0.025), min_space)
r = random.random()
if r > 0.75:
lo += vec2(inc)
layers.append( (
vec2(lo.x, hi.y),
lo,
vec2(hi.x, lo.y),
) )
elif r > 0.5:
lo += vec2(inc, 0)
hi -= vec2(0, inc)
layers.append( (
lo,
vec2(lo.x, hi.y),
hi,
) )
elif r > 0.25:
lo += vec2(0, inc)
hi -= vec2(inc, 0)
layers.append( (
lo,
vec2(hi.x, lo.y),
hi,
) )
else:
hi -= vec2(inc)
layers.append( (
vec2(lo.x, hi.y),
hi,
vec2(hi.x, lo.y),
) )
layers.pop()
for r in range(grid_size):
for c in range(grid_size):
origin = vec2(spacing+c*(scale+spacing), spacing+r*(scale+spacing))
p.goto(*origin)
p.lineto(*(origin+scale*vec2(1, 0)))
p.lineto(*(origin+scale*vec2(1)))
p.lineto(*(origin+scale*vec2(0, 1)))
p.lineto(*origin)
for s, m, e in layers:
p.goto(*(origin+scale*s))
p.lineto(*(origin+scale*m))
p.lineto(*(origin+scale*e))