module.exports = { // These are functions that can be called "From the page", // rather than being internal to the sketch. This is useful // for making on-page controls hook into the sketch code. statics: { keyHandlingOptions: { propName: "steps", values: { "38": 1, // up arrow "40": -1 // down arrow }, controller: function(api) { if (api.steps < 1) { api.steps = 1; } } } }, /** * Set up the default quadratic curve. */ setupQuadratic: function(api) { var curve = api.getDefaultQuadratic(); api.setCurve(curve); api.steps = 10; }, /** * Set up the default cubic curve. */ setupCubic: function(api) { var curve = api.getDefaultCubic(); api.setCurve(curve); api.steps = 16; }, /** * Draw a curve and its polygon-approximation, * showing the "true" length of the curve vs. the * length based on tallying up the polygon sections. */ draw: function(api, curve) { api.reset(); api.drawSkeleton(curve); var pts = curve.getLUT(api.steps); var step = 1 / api.steps; var p0 = curve.points[0], pc; for(var t=step; t<1.0+step; t+=step) { pc = curve.get(Math.min(t,1)); api.setColor("red"); api.drawLine(p0,pc); p0 = pc; } var len = curve.length(); var alen = 0; for(var i=0,p1,dx,dy; i