-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsvg_testgrid.pyde
80 lines (67 loc) · 1.79 KB
/
svg_testgrid.pyde
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
# For Processing v.3.5.4 ONLY.
# Does NOT work with Python Mode for Processing 4+,
# Owing to incompatibility with SVG Export Library.
#
# Draws a grid of lines. Good for testing the plotter.
# The lines are ordered to give you the quickest overview
# of whether things are aligned properly :)
#
# For more information on the Processing SVG library, see:
# https://processing.org/reference/libraries/svg/index.html
add_library('svg')
def setup():
# Letter: 11"x8.5" at 96 DPI.
size(1056, 816)
# Only run once:
noLoop()
def draw():
background(255)
beginRecord(SVG, "testgrid_from_processing_py.svg");
dpi = 96
margin = dpi * 0.5
L = margin
R = width-margin
T = margin
B = height-margin
noFill()
stroke(0,0,0)
strokeWeight(1.0)
# Draw the outer rectangle first
beginShape()
vertex(L,T)
vertex(R,T)
vertex(R,B)
vertex(L,B)
vertex(L,T)
endShape(CLOSE)
# half-inch grid.
gridSize = 0.5;
nDivsX = (int)((R-L)/(dpi * gridSize))
nDivsY = (int)((B-T)/(dpi * gridSize))
# Draw the even grid lines
for i in range(2, nDivsX, 2):
x = map(i, 0,nDivsX, L,R);
if i % 4 == 0:
line(x,B, x,T)
else:
line(x,T, x,B)
for i in range(2, nDivsY, 2):
y = map(i, 0,nDivsY, T,B)
if i % 4 == 0:
line(R,y, L,y)
else:
line(L,y, R,y)
# Draw the odd grid lines
for i in range(1, nDivsX, 2):
x = map(i, 0,nDivsX, L,R)
if (i-1)%4 == 0:
line(x,B, x,T)
else:
line(x,T, x,B)
for i in range(1, nDivsY, 2):
y = map(i, 0,nDivsY, T,B)
if (i-1)%4 == 0:
line(R,y, L,y)
else:
line(L,y, R,y)
endRecord()