-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcode_from_image.pde
55 lines (43 loc) · 1.6 KB
/
gcode_from_image.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
PImage theImage;
float feedRate = 80;
float depth = 0.5;
float clearance = 0.75;
float pixelDim = 0.006;
int stepover = 8;
float xPos;
float yPos;
float zPos;
Data gCodeFile;
void setup( ) {
gCodeFile = new Data();
frameRate(120);
theImage = loadImage( dataPath( "green-man-bw.jpg" ) );
gCodeFile.beginSave();
gCodeFile.add( "G20 G90 G40" );
gCodeFile.add( "G0 Z0.25" );
gCodeFile.add( "T0 M6" );
gCodeFile.add( "G17" );
gCodeFile.add( "M3" );
for ( float y = stepover; y < theImage.height; y += stepover ) {
for ( float x = stepover; x < theImage.width; x++ ) {
xPos = x * pixelDim;
yPos = y * pixelDim;
float zVal = brightness( theImage.pixels[ int(y) * theImage.width + int(x) ] );
zPos = map( zVal, 0, 255, 0, depth );
gCodeFile.add( "G1 X" + xPos + " Y" + yPos + " Z" + zPos + " F" + feedRate );
//println("X" + xPos + " Y" + yPos);
}
gCodeFile.add( "G1 Z" + clearance + " F" + feedRate );
gCodeFile.add( "G0 " + "X " + 0 + " Y" + yPos);
}
gCodeFile.add( "M5" );
gCodeFile.add( "M30" );
String datestamp = year() + "_" +
nf( month(), 2 ) + "_" +
nf( day(), 2 ) + "_" +
nf( hour(), 2 ) + "_" +
nf( second(), 2 );
gCodeFile.endSave( dataPath( "gCode-" + datestamp + ".nc" ));
}
void draw( ) {
}