-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcode.html
64 lines (56 loc) · 1.3 KB
/
gcode.html
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
<pre>
<script>
mill = 6;
command = function(parts) {
document.write(parts.join(" ")+"\n");
}
sanitize = function(_var)
{
return typeof(_var)=="number" ? _var.toFixed(3) : _var;
}
straightFeed = function(x, y, z, speed)
{
params = ["G1", "X"+sanitize(x), "Y"+sanitize(y), "Z"+sanitize(z), "F"+sanitize(speed)];
if (typeof(x) == "object")
{
params = ["G1"];
for (key in x)
{
params.push(key.toUpperCase()+sanitize(x[key]));
}
}
command(params);
}
feed = function(x, y, z, speed)
{
params = ["G0", "X"+sanitize(x), "Y"+sanitize(y), "Z"+sanitize(z), "F"+sanitize(speed)];
if (typeof(x) == "object")
{
params = ["G0"];
for (key in x)
{
params.push(key.toUpperCase()+sanitize(x[key]));
}
}
command(params);
}
hex = function(x, y, s) {
feed({z: -4});
for (r = 0.0; r<s/2-mill/2; r+= 5.0)
for (a = Math.PI/6.0; a <= Math.PI*13/6.0; a+=Math.PI/3.0)
straightFeed({x: x+r*Math.cos(a), y: y+r*Math.sin(a)});
feed({z: -1});
r=s/2;
for (a = Math.PI/6.0; a <= Math.PI*13/6.0; a+=Math.PI/3.0)
straightFeed({x: x+r*Math.cos(a), y: y+r*Math.sin(a)});
}
command(["%"]);
hex(0,0,112);
for (B = Math.PI/6.0; B <= Math.PI*2; B+=Math.PI/3.0)
{
console.log(B);
hex(100*Math.cos(B), 100*Math.sin(B), 112);
}
command(["%"]);
</script>
</pre>