JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<pre>
<input type="button" id="downloadButton" value="Download this G-code" >
<div id="spring"></div>
</pre>
</body>
JavaScript
"use strict"
// Helper functions to shim java library calls into javascript.
var outg = {
outstring: "",
println: function (str) {
this.outstring += str + "\r\n";
}
};
// Simple replacement for String.Format that only replaces float entities with js text representations of variables (truncated)
// Could use JS string functions instead, but this is compatible with older browsers.
var myStringFn = {
format: function (instr, ...vals) {
for (var curr = 0; curr < vals.length; curr++) {
var curstr = curr == 0 ? '' : curr + 1;
var replaceStr = "%" + curstr + "f";
var value = "" + vals[curr];
var dotPos = value.indexOf('.');
if (dotPos != -1) {
instr = instr.replace(replaceStr, value.substring(0, dotPos + 7));
} else {
instr = instr.replace(replaceStr, value);
}
}
return instr;
},
printf: function (fstring, ...vals) {
outg.println(myStringFn.format(fstring, ...vals));
}
};
var jsMath = {
toRadians: function (val) {
return val * Math.PI / 180;
}
};
function coOrd(x, y, z) {
var obj = this;
this.x = x;
this.y = y;
this.z = z;
this.fn = {};
// Return a new object that is the difference between the object and the parameter object.
this.fn.difference = function (d) { return new coOrd(obj.x - d.x, obj.y - d.y, obj.z - d.z) };
//Update the x/y/z of current object based on parameter.
this.fn.setFrom = function (newD) { obj.x = newD.x; obj.y = newD.y; obj.z = newD.z; };
}
var MagicSpring = {};
MagicSpring.fn = { ancestor: MagicSpring };
// Initialise all parameters - this includes an inner init function for derived parameters.
MagicSpring.fn.init = function () {
this.ancestor.params = {
hotendTemp: 200,
bedTemp: 50,
avr: 32.5,
width: 5,
layerHeight: .4,
delta: 1,
angle: 0, //Starting angle, not used yet.
maxHeight: 70,
extrudeMult: 0.026,
fudgeFactor: 0.45,
startPosition: { x: 5, y: 10, z: 0.05 },
e: 0,
...