-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhexpaths.py
More file actions
86 lines (70 loc) · 2.44 KB
/
Copy pathhexpaths.py
File metadata and controls
86 lines (70 loc) · 2.44 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
from math import floor
from random import *
from geometer import *
def three_right(hex):
points = hex.points
return (
(Arc(hex.size / 2, 120), points[1], 120),
(Arc(hex.size / 2, 120), points[3], 0),
(Arc(hex.size / 2, 120), points[5], -120)
)
def three_left(hex):
points = hex.points
return (
(Arc(hex.size / 2, 120), points[0], 180),
(Arc(hex.size / 2, 120), points[2], 60),
(Arc(hex.size / 2, 120), points[4], -60)
)
def two_up(hex):
points = hex.points
return (
(Arc(hex.size / 2, 120), points[4], -60),
(Line(
Line(points[2], points[3]).midpoint,
Line(points[0], points[5]).midpoint), None, None),
(Arc(hex.size / 2, 120), points[1], 120)
)
def two_pos(hex):
points = hex.points
return (
(Arc(hex.size / 2, 120), points[5], -120),
(Line(
Line(points[0], points[1]).midpoint,
Line(points[3], points[4]).midpoint), None, None),
(Arc(hex.size / 2, 120), points[2], 60)
)
def two_neg(hex):
points = hex.points
return (
(Arc(hex.size / 2, 120), points[0], 180),
(Line(
Line(points[1], points[2]).midpoint,
Line(points[4], points[5]).midpoint), None, None),
(Arc(hex.size / 2, 120), points[3], 0)
)
def draw(canvas):
size = 128
color_center = canvas.random_point()
longest = canvas.longest_distance_from(color_center)
stroke_color = canvas.stroke_color
g = VerticalHexagonGrid(canvas.center, size, floor(canvas.width / size), floor(canvas.height / size))
# g = VerticalHexagonGrid(canvas.center, size, 6, 6)
for idx, p in enumerate(g.points):
d = p.distance_to(color_center)
# h = HorizontalHexagon(g.size - g.r, p)
# h = HorizontalHexagon(size, p)
h = HorizontalHexagon(g.step - g.r, p)
# canvas.set_stroke_width(1)
# canvas.set_stroke_color(white.half())
# h.draw(canvas)
canvas.set_stroke_width(4)
canvas.set_stroke_color(band(fills, d, longest, fuzz=True))
# f = random.choice((three_left, three_right, two_up, two_pos, two_neg))
f = [two_neg, two_pos][idx % 2]
operations = f(h)
for shape, at, rotation in operations:
if at:
shape.draw(canvas, at_point=at, rotation=rotation)
else:
shape.draw(canvas)