-
Notifications
You must be signed in to change notification settings - Fork 0
/
prison.py
179 lines (134 loc) · 4.58 KB
/
prison.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import noise
transparent_bg = True
# 1 : boxes only
# 2 : lines only
# 3 : 3d boxes
mode = 3
s_mode = 4
mode_adjustment = 1
use_cmyk = True
if s_mode == 1: # Poster
size('A3')
n_w = 19
elif s_mode == 2: # Facebook
size(1702, 630)
n_w = 60
mode_adjustment = 1.2
use_cmyk = False
elif s_mode == 3: # Twitter
size(1500, 500)
n_w = 53
mode_adjustment = 1.3
use_cmyk = False
elif s_mode == 4: # Site background texture
size(1280, 640)
n_w = 22
use_cmyk = False
elif s_mode == 5: # Instagram Post
size(1080, 1080)
n_w = 33
mode_adjustment = 1.8
use_cmyk = False
elif s_mode == 6: # Youtube cover
size(2560, 1440)
n_w = 80
use_cmyk = False
if not transparent_bg:
if use_cmyk:
cmykFill(0,0,0,1)
else:
fill(0)
rect(0,0,width(),height())
# how many rows for a given (n_w) number of columns?
n_h = round(n_w * height()/width())
# if the width is too wide, change the number of columns to its minimum
# value considering square unites
if n_h == 0:
n_h = 1
aux_n_w = n_w
n_w = round(width()/height())
print(f'Too few squares to fill this page! \nYou’d need {n_w} squares, so we went ahead and overrode your initial setting of {aux_n_w}!')
# this calculates the width and height of each “square”
# (which will be as square as possible, but rarely so)
w = (width())/n_w
h = (height())/n_h
# dras the grid
for _x in range(n_w):
for _y in range(n_h):
# first coordinates of the bigger square
x0 = _x * w
y0 = _y * h
# part perlin, half noise
perlin = 0.95
rx = perlin * abs(noise.pnoise1(_x/n_w, repeat=n_w)) + (1-perlin) * random()
ry = perlin * abs(noise.pnoise1(_y/n_h, repeat=n_h)) + (1-perlin) * random()
frac = min([0.9, 0.2 + 0.4 * rx + 0.4 * ry])
# sometimes i'll need smaller or bigger gaps
frac = min([0.9, frac*mode_adjustment])
# the size of the gap
small_s = w * frac
# first coordinates of the smaller square
sx0 = x0 + rx * (1 - frac) * w
sy0 = y0 + ry * (1 - frac) * h
# second coordinates of the bigger square
x1 = x0 + w
y1 = y0 + h
# second coordinates of the smaller square
sx1 = sx0 + small_s
sy1 = sy0 + small_s
# only squares
if mode == 1:
stroke(1)
if use_cmyk:
cmykFill(.18, 1, .25, 0)
else:
fill(210/255, 9/255, 119/255)
rect(x0, y0, w, h)
stroke(None)
if use_cmyk:
cmykFill(.48, 1, .48, .48)
else:
fill(93/255, 5/255, 58/255)
rect(sx0, sy0, small_s, small_s)
# only lines
if mode == 2:
fill(None)
if use_cmyk:
cmykStroke(.18, 1, .25, 0)
else:
stroke(210/255, 9/255, 119/255)
# Left
polygon((x0, y0), (x0, y1), (sx0, sy1), (sx0, sy0), close = True)
# Right
polygon((x1, y1), (x1, y0), (sx1, sy0), (sx1, sy1), close = True)
# Top
polygon((x0, y1), (x1, y1), (sx1, sy1), (sx0, sy1), close = True)
# Bottom
polygon((x0, y0), (x1, y0), (sx1, sy0), (sx0, sy0), close = True)
# faux 3d
if mode == 3:
stroke(None)
# Left
if use_cmyk:
cmykFill(.29, 1, .29, .19)
else:
fill(160/255, 11/255, 100/255)
polygon((x0, y0), (x0, y1), (sx0, sy1), (sx0, sy0), close = True)
# Right
if use_cmyk:
cmykFill(.18, 1, .25, 0)
else:
fill(210/255, 9/255, 119/255)
polygon((x1, y1), (x1, y0), (sx1, sy0), (sx1, sy1), close = True)
# Top
if use_cmyk:
cmykFill(.48, 1, .48, .48)
else:
fill(93/255, 5/255, 58/255)
polygon((x0, y1), (x1, y1), (sx1, sy1), (sx0, sy1), close = True)
# Bottom
if use_cmyk:
cmykFill(0, .73, 0, .13)
else:
fill(214/255, 82/255, 149/255)
polygon((x0, y0), (x1, y0), (sx1, sy0), (sx0, sy0), close = True)