Created
September 30, 2019 04:43
-
-
Save cceckman/e87b613ca2f704ceece5775aa4267d4c to your computer and use it in GitHub Desktop.
JS Stitch calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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