-
Notifications
You must be signed in to change notification settings - Fork 0
/
art_card_2021_may.py
120 lines (98 loc) · 3.67 KB
/
art_card_2021_may.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
# hatching polygons of various shapes or whatever
from cortexdraw import *
# generate a list of irregular polygons laid out in a checkerboard arrangement
def getpolyfield(w=8, h=5, length=10):
quads = []
for i in range(w):
for j in range(h):
# growth = 0
growth = (random.random() - 0.5) * 0.5
x1 = (i - growth) * length
y1 = (j - growth) * length
x2 = (i + 1 + growth) * length
y2 = (j + 1 + growth) * length
newsq = [[x1, y1], [x1, y2], [x2, y2], [x2, y1]]
quads.append(newsq)
return quads
# return a squared-off grid with random intervals for each row and column
def getunevengrid(w=7, h=6, length=10):
quads = []
# generate a set of intervals
dx = [0]
dy = [0]
for i in range(w):
# dx.append( (random.random() - 0.5)*(length) + length + dx[-1])
dx.append((random.random() + 0.25) * length + dx[-1])
for j in range(h):
# dy.append( (random.random() - 0.5)*(length) + length + dy[-1])
dy.append((random.random() + 0.25) * length + dy[-1])
# and then normalize them
sumx = w * length / dx[-1]
sumy = h * length / dy[-1]
for i in range(len(dx)):
dx[i] *= sumx
for i in range(len(dy)):
dy[i] *= sumy
# and then turn 'em into squares
for i in range(w):
for j in range(h):
x1 = dx[i]
y1 = dy[j]
x2 = dx[i + 1]
y2 = dy[j + 1]
newsq = [[x1, y1], [x1, y2], [x2, y2], [x2, y1]]
quads.append(newsq)
return quads
# generate a connected net of perturbed squares
def getperturbedgrid(w=8, h=7, length=10):
polys = []
mag = length * 1
# generate grid vertices from which net of polygons will be constructed
points = [None] * (w + 1)
for i in range(w + 1):
points[i] = [None] * (h + 1)
for j in range(h + 1):
# points[i][j] = [i*len,j*len]
# do some perturbation...
points[i][j] = [i * length + (random.random() - 0.5) * mag, j * length + (random.random() - 0.5) * mag]
# ...and then construct actual polygon objects from vertices
for i in range(w):
for j in range(h):
newsq = [points[i][j], points[i][j + 1], points[i + 1][j + 1], points[i + 1][j]]
polys.append(newsq)
return polys
width = 4
height = 3
length = 8
fig = plt.figure(figsize=(12, 9), dpi=100, frameon=False)
axs = makeaxesgrid(fig, 4, 2, 2)
permagrid = getunevengrid(width, height, length)
count = 0
for a in axs:
patches = []
# quads = getunevengrid(width,height,length)
# quads = getperturbedgrid(width,height,length)
quads = copy.deepcopy(permagrid)
for q in quads:
# q = jitter(q,2,True)
# patches.append(mpatches.Polygon(q,closed=True,fill=None, color="black"))
# hatching = crophatch(q, random.random()*math.pi*0.2, random.random()/4 +.25)
# if(random.random() > 0.1): continue
hatching = crophatch(q, random.random() * math.pi, random.random() / 3 + .25)
# hatching = circuitpolyline(q,int(random.random() * 20)+10)
for line in hatching:
# if(random.random() > 0.5): continue
line = jitter(line, 0.1, True)
patches.append(mpatches.Polygon(line, closed=False, fill=None))
count += 1
collection = PatchCollection(patches, match_original=True)
a.add_collection(collection)
x_bounds = [-5, width * length + 5]
y_bounds = [-5, height * length + 5]
writefigure(fig,
xbounds=x_bounds,
ybounds=y_bounds,
name="art_card_2021_may",
pagesize=[14, 11],
drawingsize=[12, 9])
plt.show()