bendy-line-thing-2.js

total 0
used 0
limit 0
/* title: Elbow Constraints category: constraints files: head point stroke ../point_src/point-content.js pointlist mouse dragging ../point_src/distances.js ../point_src/functions/clamp.js ../point_src/mirror.js ../point_src/stage.js ../point_src/text/label.js ../point_src/intersections.js ../point_src/cone.js ../point_src/easing.js ../point_src/constrain-distance.js --- An elbow contraint ensures a target point is _connected_ to another point, at a distance of the two radii. point.constraint.elbow(other) It's called an elbow, as there will always be an intersection at the max distance. Similar to rings bound at the edge. Synonymous to: let pA = this.legL let pB = this.primaryPoint pA.leash(pointB, (pB.radius + pA.radius) - .01) pA.avoid(pointB, Math.abs(pB.radius - pA.radius) + .01) */ class MainStage extends Stage { canvas='playspace' mounted(){ console.log('main') this.a = new PointList( {x:180,y:360, radius:20} , {x:200,y:320, radius:20} , {x:240,y:290, radius:20} , {x:240,y:240, radius:20} , {x:250,y:170, radius:20} , {x:350,y:240, radius:20} ).cast() this.b = new Point({x:390,y:220, radius:130}) this.dragging.addPoints(...this.a, this.b) } draw(ctx){ this.clear(ctx) /* hip leashes knee */ // this.a[2].constraint.leash(this.a[1], 100) /* Knee leashes foot */ // this.a[1].constraint.leash(this.a[0], 100) /* Knee looks away from hip*/ let orig = this.a; let lineCurve = this.genLine(orig) // a1.pen.indicator(ctx) // this.a.pen.indicator(ctx, {color: 'cyan'}) this.b.pen.indicator(ctx) orig.pen.indicator(ctx, {color: '#444'}) // lineCurve.pen.indicator(ctx, {color: 'orange'}) // orig[2].pen.indicator(ctx, {color: 'green'}) // lineCurve.pen.quadCurve(ctx, {color: 'red', width: 2, loop:true}) // lineCurve.pen.quadCurve(ctx, {color: 'pink', width: 2, loop:false}) lineCurve.pen.line(ctx, {color: 'pink', width: 2, loop:false}) } genLine(orig){ let getPair = function(fromIndex=0, centerIndex=1, toIndex=2) { let r = orig[centerIndex].rotation orig[centerIndex].lookAt(orig[fromIndex]) let a1 = orig[centerIndex].project() orig[centerIndex].lookAt(orig[toIndex]) let a2 = orig[centerIndex].project() orig[centerIndex].rotation = r return [a1, a2] } const quadEaseOut = function(t) { return -(t * (t - 2)) } const circularEaseInOut = function(t) { if( t < 0.5){ return 0.5 * (1 - Math.sqrt(1 - 4 * (t * t))) } return 0.5 * (Math.sqrt(-((2 * t) - 3) * ((2 * t) - 1)) + 1) } let triple = function(fromIndex=0, centerIndex=1, toIndex=2, easingName) { let ab = getPair(fromIndex, centerIndex, toIndex) let c = orig[centerIndex].copy() c.lookAt(ab[0].midpoint(ab[1])) let real = c.radius - (ab[0].distanceTo(ab[1])) * .5 if(easingName) { real = c.radius * easingFunctions[easingName][easingType](real / c.radius) } c = c.project(real) // return [ab[0], orig[centerIndex], ab[1]] return [ab[0], c, ab[1]] } let tipA = function(beforeIndex, index, toTip=true, easingName) { let origR = orig[index].rotation // orig[index].lookAt(orig.last()) let a1 = orig[index].project() orig[index].lookAt(orig[beforeIndex]) let a2 = orig[index] if(toTip) { a2 = a2.project() } orig[index].rotation = origR if(!toTip) { return [a2, orig[index]] } let c = orig[index].copy() if(easingName) { c.lookAt(a1.midpoint(a2)) let real = c.radius - (a1.distanceTo(a2)) * .5 real = c.radius * easingFunctions[easingName][easingType](real / c.radius) c = c.project(real) } return [a1, c, a2] } let tipB = function(beforeIndex, index, toTip=true, easingName) { let origR = orig[index].rotation orig[index].lookAt(orig[beforeIndex]) let a1 = orig[index] if(toTip) { a1 = a1.project() } orig[index].rotation = origR let a2 = orig[index].project() let c = orig[index].copy() if(easingName) { c.lookAt(a1.midpoint(a2)) let real = c.radius - (a1.distanceTo(a2)) * .5 real = c.radius * easingFunctions[easingName][easingType](real / c.radius) c = c.project(real) } if(!toTip) { return [a1, orig[index]] } return [a1, c, a2] } let items = orig//.slice(1, stage.a.length-1) let toTip = true; let easingName = 'sine' let easingType = 'out' // orig[1].constraint.cone(orig[2], 90) let lineCurve = new PointList( ...tipA(1, 0, toTip, easingName) // , ...triple(0, 1, 2) // , ...triple(1, 2, 3) // , ...triple(2, 3, 4) // , ...tipB(3, 4, toTip) ).cast() items.forEach((e,i, a) => { if(i == 0 || i == items.length-1) { return } lineCurve.push(...triple(i-1, i, i+1, easingName)) }) lineCurve.push(...tipB(items.length-2, items.length-1, toTip, easingName)); return lineCurve } } ;stage = MainStage.go();
Run
Meta Data
title Elbow Constraints
imports ()
files ('head', 'point', 'stroke', '../point_src/point-content.js', 'pointlist', 'mouse', 'dragging', '../point_src/distances.js', '../point_src/functions/clamp.js', '../point_src/mirror.js', '../point_src/stage.js', '../point_src/text/label.js', '../point_src/intersections.js', '../point_src/cone.js', '../point_src/easing.js', '../point_src/constrain-distance.js')
unused_keys ()
unknown_keys ('category',)
category ['constraints']
filepath_exists True
path bendy-line-thing-2.js
filepath bendy-line-thing-2.js
clean_files ('../point_src/core/head.js', '../point_src/pointpen.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.js', '../point_src/pointdraw.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/setunset.js', '../point_src/stroke.js', '../point_src/pointlistdraw.js', '../point_src/pointlistgradient.js', '../point_src/pointlistshape.js', '../point_src/pointlistgenerator.js', '../point_src/unpack.js', '../point_src/pointlist.js', '../point_src/pointlistpen.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/functions/clamp.js', '../point_src/distances.js', '../point_src/protractor.js', '../point_src/text/beta.js', '../point_src/dragging.js', '../point_src/mirror.js', '../point_src/stage-hooks.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/text/label.js', '../point_src/intersections.js', '../point_src/cone.js', '../point_src/easing.js', '../point_src/constrain-distance.js')
markdown {'html': "<p>An elbow contraint ensures a target point is <em>connected</em> to another point, at\na distance of the two radii.</p>\n<pre><code> point.constraint.elbow(other)\n</code></pre>\n<p>It's called an elbow, as there will always be an intersection at the max distance.\nSimilar to rings bound at the edge.</p>\n<p>Synonymous to:</p>\n<pre><code>let pA = this.legL\nlet pB = this.primaryPoint\n\npA.leash(pointB,\n (pB.radius + pA.radius) - .01)\npA.avoid(pointB,\n Math.abs(pB.radius - pA.radius) + .01)\n</code></pre>", 'content': "title: Elbow Constraints\ncategory: constraints\nfiles:\n head\n point\n stroke\n ../point_src/point-content.js\n pointlist\n mouse\n dragging\n ../point_src/distances.js\n ../point_src/functions/clamp.js\n ../point_src/mirror.js\n ../point_src/stage.js\n ../point_src/text/label.js\n ../point_src/intersections.js\n ../point_src/cone.js\n ../point_src/easing.js\n ../point_src/constrain-distance.js\n---\n\nAn elbow contraint ensures a target point is _connected_ to another point, at\na distance of the two radii.\n\n point.constraint.elbow(other)\n\nIt's called an elbow, as there will always be an intersection at the max distance.\nSimilar to rings bound at the edge.\n\nSynonymous to:\n\n let pA = this.legL\n let pB = this.primaryPoint\n\n pA.leash(pointB,\n (pB.radius + pA.radius) - .01)\n pA.avoid(pointB,\n Math.abs(pB.radius - pA.radius) + .01)"}