-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsvg_testgrid.pde
77 lines (69 loc) · 1.58 KB
/
svg_testgrid.pde
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
// 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 :)
//-----------------------
import processing.svg.*;
void setup() {
size(1056, 816); // Letter: 11"x8.5" at 96 DPI.
noLoop();
}
//-----------------------
void draw() {
background(255);
beginRecord(SVG, "testgrid_from_processing.svg");
float dpi = 96;
float margin = dpi * 0.5;
float L = margin;
float R = width-margin;
float T = margin;
float 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);
float gridSize = 0.5; // half-inch grid.
int nDivsX = (int)((R-L)/(dpi * gridSize));
int nDivsY = (int)((B-T)/(dpi * gridSize));
// Draw the even grid lines
for (int i=2; i<nDivsX; i+=2){
float x = map(i, 0,nDivsX, L,R);
if (i%4 == 0){
line(x,B, x,T);
} else {
line(x,T, x,B);
}
}
for (int i=2; i<nDivsY; i+=2){
float 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 (int i=1; i<nDivsX; i+=2){
float x = map(i, 0,nDivsX, L,R);
if ((i-1)%4 == 0){
line(x,B, x,T);
} else {
line(x,T, x,B);
}
}
for (int i=1; i<nDivsY; i+=2){
float y = map(i, 0,nDivsY, T,B);
if ((i-1)%4 == 0){
line(R,y, L,y);
} else {
line(L,y, R,y);
}
}
endRecord();
}