Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Foolish Quest: Auto-Generating Knitting Patte...

Liz
June 20, 2016

A Foolish Quest: Auto-Generating Knitting Patterns with JavaScript

Taking something real-world and math-based, like knitting, and turning into a program is actually super easy (no one is surprised here). But! What happens when you combine that with best practices and expected conventions, along with industry-wide standards for design and presentation? Things get a lot more complicated than just crunching numbers, especially when your output will result in lots of manual hours creating a real object. This is the story of how I built a customizable knitting pattern generator in JavaScript (after I built it in Ruby first, of course), and the lessons learned when you try and do math for more than just math's sake.

Liz

June 20, 2016
Tweet

More Decks by Liz

Other Decks in Programming

Transcript

  1. LIZ ABINANTE PRESENTS her foolish quest to auto-generate knitting patterns

    using JavaScript. @feministy • [email protected] Senior Software Engineer, New Relic
  2. What even is a knitting pattern? A set of instructions,

    schematics, photos, and charts to reproduce a given item with reasonable consistency
  3. Other garments Any time you add people shaped things into

    your math, it needs to be more precise than just math
  4. let gauge = 19 let circumference = 19 let rawCastOn

    = (gauge / 4) * circumference let roundDown = roundDownToFour(rawCastOn) let roundUp = roundUpToFour(rawCastOn) let castOn =
  5. let gauge = 19 let circumference = 19 let rawCastOn

    = 90.25 let roundDown = 88 let roundUp = 92 let castOn =
  6. let gauge = 6 let desiredSize = 28 let rawCastOn

    = 42 let roundDown = roundDownToFour(rawCastOn) let roundUp = roundDownToFour(rawCastOn) let castOn =
  7. let gauge = 19 let circumference = 23.5 let rawCastOn

    = 111.6 let roundDown = roundDownTo13(rawCastOn) let roundUp = roundUpTo13(rawCastOn) let castOn =
  8. let gauge = 19 let circumference = 23.5 let rawCastOn

    = 111.6 let roundDown = roundDownTo13(rawCastOn) let roundUp = roundUpTo13(rawCastOn) let castOn =
  9. Imperial -> Metric Imperial numbers are larger units that translate

    awkwardly to centimeters Rounding comes back to bite you, again
  10. Metric -> Imperial Metric units are more precise and often

    result in difficult-to-measure imperial numbers Rounding comes back to bite you, again
  11. tl;dr Solve all of your unit conversion problems by doing

    2 sets of calculations and simply choosing the best one
  12. tl;dr An experienced designer can make a judgement call for

    which results to use JAVASCRIPT CAN’T DO THAT
  13. JavaScript can’t even Take the integrity of a design into

    account when scaling up or down for different sizes
  14. JavaScript can’t even Make modifications to large stitch motifs that

    are otherwise unnoticeable but will make an awkward number work
  15. JavaScript can’t even Make a decision about when to break

    from an algorithm and do something different to make a size or design work
  16. If you’re thinking machine learning ok fine i get it

    you’re right i’m wrong javascript can do anything yayyyy
  17. Image credits Knit hat: https://unsplash.com/photos/hAobD5OjoHE Fire: https://www.pexels.com/photo/wood-explosion-fire-hot-8504/ Math equation: https://unsplash.com/photos/5mZ_M06Fc9g

    Stack of knit hats: http://www.purlsoho.com/create/2014/10/22/ classic-cuffed-hat/ All other images are mine (insert evil laughter here)