Skip to content

Instantly share code, notes, and snippets.

@cceckman
Created September 30, 2019 04:43
Show Gist options
  • Save cceckman/e87b613ca2f704ceece5775aa4267d4c to your computer and use it in GitHub Desktop.
Save cceckman/e87b613ca2f704ceece5775aa4267d4c to your computer and use it in GitHub Desktop.
JS Stitch calculator
var inputs = {
swatch: {
stitches: 20,
length: 4 # Really any unit, as long as it's the same as target_length
},
pattern: {
multiple: 6,
plus: 2
},
target_length: 21 # Really any unit, as long as it's the same as swatch.length
};
function estimate(inputs) {
var gauge = (inputs.swatch.stitches) / (inputs.swatch.length);
console.log("using gauge: ", gauge);
var est_sts = (inputs.target_length) * gauge;
console.log("estimated stitches: ", est_sts);
var est_repeats = (est_sts - inputs.pattern.plus) / inputs.pattern.multiple;
console.log("estimated repeats: ", est_repeats);
return {
target_sts: est_sts,
lower: (Math.floor(est_repeats) * inputs.pattern.multiple) + inputs.pattern.plus,
upper: (Math.ceil(est_repeats) * inputs.pattern.multiple) + inputs.pattern.plus
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment