-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_patterns.py
More file actions
97 lines (75 loc) · 2.18 KB
/
generate_patterns.py
File metadata and controls
97 lines (75 loc) · 2.18 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
87
88
89
90
91
92
93
94
95
96
97
HASH_CHARS = '!@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
NUM_COLORS = 7
def with_value(value=0.0, *, num_colors=7):
return [[value for x in range(num_colors + 1)] for y in range(num_colors)]
def encode(m):
def encode_row(row):
return ''.join(HASH_CHARS[int((x + 0.25) * len(HASH_CHARS))] for x in row)
return ''.join(encode_row(r) for r in m)
def likes_self(num_colors=NUM_COLORS):
m = with_value(-0.1, num_colors=num_colors)
for x in range(num_colors):
m[x][0] = 0.2
m[x][x + 1] = 0.74
return m
def red_kernels(num_colors=NUM_COLORS):
m = with_value(-0.1, num_colors=num_colors)
for x in range(num_colors):
m[x][0] = 0
if x > 0:
m[x][1] = 0.74
return m
def neighbors(num_colors=NUM_COLORS):
m = with_value(-0.1)
for x in range(num_colors):
m[x][0] = 0
m[x][x + 1] = -0.25
x1 = 1 + (x + 1) % num_colors
m[x][x1] = 0.5
return m
def middle(num_colors=NUM_COLORS):
m = with_value(0.2)
for x in range(num_colors):
m[x][0] = -0.25
m[x][x + 1] = 0.5
return m
def popular(num_colors=NUM_COLORS):
m = with_value(0)
for x in range(num_colors):
m[x][0] = -0.1
f = x / (num_colors * 2)
for y in range(num_colors):
m[x][y + 1] = f
if x == y:
m[x][y + 1] += 0.2
return m
def circle(num_colors=3):
m = with_value(-0.2, num_colors=num_colors)
for x in range(num_colors):
y = (x + 1) % num_colors
m[x][0] = 0.1
m[x][y + 1] = 0.74
return m
def no_love(num_colors=3):
m = with_value(-0.2, num_colors=num_colors)
for x in range(num_colors):
m[x][0] = 0.0
return m
for fn, params in [
(likes_self, 2),
(likes_self, 5),
(red_kernels, 5),
(neighbors, None),
(middle, None),
(popular, None),
(no_love, 5),
(circle, 3),
(circle, 4),
(circle, 5)]:
name = fn.__name__.replace('_', '-')
if params is None:
params = NUM_COLORS
else:
name += '-' + str(params)
code = fn(params)
print(name, encode(code))