-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.py
52 lines (40 loc) · 1.6 KB
/
template.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
""" A minimal example drawing file to demonstrate/test basic use of cortexlib.py """
from cortexdraw import *
def get_grid_of_squares(w=8, h=5, length=10):
""" generate and return a w*h grid of squares """
newsquares = []
for i in range(w):
for j in range(h):
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]]
newsquares.append(newsq)
return newsquares
# establish some arbitrary-to-the-drawing dimensional values for the drawing
width = 12
height = 9
linelength = 10
# create a new artwork with a single layer
art = new_artwork()
# add some more layers for additional distinct drawing passes
art = add_layer(art)
art = add_layer(art)
art = add_layer(art)
# generate some geometry with a drawing function and store it
squares = get_grid_of_squares(width, height, linelength)
# do something with for each layer of the drawing
for a in art.axes:
patches = []
quads = copy.deepcopy(squares)
for q in quads:
hatching = crophatch(q, random.random() * math.pi + 0.1, random.random() * math.pi + 0.1)
for line in hatching:
patches.append(mpatches.Polygon(line, closed=False, fill=None))
collection = PatchCollection(patches, match_original=True)
a.add_collection(collection)
x_bounds = [-5, width * linelength + 5]
y_bounds = [-5, height * linelength + 5]
writefigure(art, xbounds=x_bounds, ybounds=y_bounds, name="template")