-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.pde
More file actions
68 lines (48 loc) · 1.73 KB
/
build.pde
File metadata and controls
68 lines (48 loc) · 1.73 KB
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
void buildModel() {
//load the ggcode file
gCode = loadStrings( dataPath("gCode-tight.nc") );
model = new UVertexList();
for ( int i = 0; i < gCode.length; i++ ) {
//parse each line. if there's a new x, y, or z value, update it
//otherwise carry over the previously set value
parseLine( lineNum, gCode );
lineNum++;
model.add(px, py, pz);
model.add(x, y, z);
px = x;
py = y;
pz = z;
}
model.calcBounds();
println( model.bb );
model.center();
}
void parseLine( int lineNum, String[] lines ) {
//grab the current line
String codeLine = lines[ lineNum ];
//parse for X, Y, Z
//assume there's a space between coordinates, eg "G0 X3.25 Y0.12 Z4.125"
String[] coords = trim( split( codeLine, " " ) );
//look at each part of the line that was divided at the space
for ( int s = 0; s < coords.length; s++ ) {
String word = trim( coords[s] );
println( word );
char first = word.charAt(0);
switch( first ) {
case 88: //X
x = float( word.substring( 1, coords[s].length() ) );
break;
case 89: //Y
y = float( word.substring( 1, coords[s].length() ) );
break;
case 90: //Z
z = float( word.substring( 1, coords[s].length() ) );
break;
}
}
}
void drawMe( UVertexList ptList, PApplet _this ){
beginShape(LINES);
model.drawVertices( _this );
endShape();
}