spring-point-collisions.js

total 0
used 0
limit 0
/* title: Graph Chain Follow Points V3 categories: springs graph files: head ../point_src/math.js ../point_src/extras.js ../point_src/point-content.js dragging pointlist point stage mouse ../point_src/graph-connections.js ../point_src/constrain-distance.js ../point_src/constrain-distance-locked.js ../point_src/collisionbox.js ../point_src/functions/springs.js ../point_src/velocity.js stroke --- In this version the pair callback method - tests for visits. --- The `followPoint` method allows a point to _follow_ another point, at a distance. This is a lot like constraints but with a _one to one_ relationship in a single direction. This _graph chain_ stores those one to one relationships, with methods to iterate the chain in two directions. This allows use to grab the standard `A -> B -> C`, and `C -> B -> A`. The graph can resolve a "star based" configuration: A C \ / B | D | E Each connection is given in a pair, from an origin node (the `head`) head = B B -> C B -> D [ -> E ] D -> E B -> A */ class MainStage extends Stage { // canvas = document.getElementById('playspace'); canvas = 'playspace' mounted(){ /* this.points = new PointList( new Point(250, 150, 10) , new Point(400, 320, 10) , new Point(300, 520, 8) , new Point(340, 580, 8) , new Point(380, 520, 8) , new Point(410, 520, 8) , new Point(450, 520, 8) , new Point(430, 520, 8) , new Point(400, 520, 8) ) */ this.points = new PointList( new Point({x:250, y:150, radius:10, vx: .1, vy: 0, mass: 1 }) , new Point({x:400, y:320, radius:10, vx: .1, vy: 0, mass: 1 }) , new Point({x:300, y:520, radius:8, vx: .1, vy: 0, mass: 1 }) , new Point({x:340, y:580, radius:8, vx: .1, vy: 0, mass: 1 }) , new Point({x:380, y:520, radius:8, vx: .1, vy: 0, mass: 1 }) , new Point({x:410, y:520, radius:8, vx: .1, vy: 0, mass: 1 }) , new Point({x:450, y:520, radius:8, vx: .1, vy: 0, mass: 1 }) , new Point({x:430, y:520, radius:8, vx: .1, vy: 0, mass: 1 }) , new Point({x:400, y:520, radius:8, vx: .1, vy: 0, mass: 1 }) ) this.collisionBox = new CollisionBox(this.points) this.g = new GraphConnections; this.head = 0 this.g.connect(0, 1, 2, 3, 4) this.g.connect(2, 5) this.g.connect(5, 6, 7, 8) this.dragging.add(...this.points) } onMousedown(ev, p) { // console.log(this.dragging._near) this.head = this.points.indexOf(this.dragging._near) } draw(ctx){ this.clear(ctx) this.collisionBox.shuffle() // let mouse = Point.mouse.position // followPoint(mouse, this.points[0], 50) let ps = this.points // ps[5].spring.to(ps[6], 30, .2, .9, undefined, .02) this.graphChain(this.head, ps) this.points.pen.indicators(ctx) // head this.points[0].pen.fill(ctx, '#992211') // tri joint this.points[2].pen.fill(ctx, '#00cc33') } graphChain(head, ps) { // let head = this.head // let ps = this.points let visits = {} let locked = new Set([head]) let pairCallback = (key, fromKey, allTargets)=>{ // console.log('from=', fromKey, 'key=', key, ) // constraints.within(ps[fromKey], ps[key], 50) // constraints.distance(ps[fromKey], ps[key], 50) ps[key].spring.to(ps[fromKey], 40, .2, .92, locked, .2) if(visits[fromKey] == undefined) { visits[fromKey] = 0 } if(visits[key] == undefined) { visits[key] = 0 } visits[fromKey] += 1 visits[key] += 1 if(visits[key] == 1){ ps[key].lookAt(ps[fromKey]) } } this.g.walkForward(head, pairCallback) } } stage = MainStage.go(/*{ loop: true }*/)
Run
Meta Data
title Graph Chain Follow Points V3
imports ()
files ('head', '../point_src/math.js', '../point_src/extras.js', '../point_src/point-content.js', 'dragging', 'pointlist', 'point', 'stage', 'mouse', '../point_src/graph-connections.js', '../point_src/constrain-distance.js', '../point_src/constrain-distance-locked.js', '../point_src/collisionbox.js', '../point_src/functions/springs.js', '../point_src/velocity.js', 'stroke')
unused_keys ()
unknown_keys ('categories',)
categories ['springs', 'graph']
filepath_exists True
path spring-point-collisions.js
filepath spring-point-collisions.js
clean_files ('../point_src/core/head.js', '../point_src/math.js', '../point_src/extras.js', '../point_src/compass.js', '../point_src/center.js', '../point_src/point-content.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/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/pointpen.js', '../point_src/pointdraw.js', '../point_src/relative-xy.js', '../point_src/pointcast.js', '../point_src/point.js', '../point_src/stage-resize.js', '../point_src/functions/resolve.js', '../point_src/stage.js', '../point_src/events.js', '../point_src/automouse.js', '../point_src/graph-connections.js', '../point_src/constrain-distance.js', '../point_src/constrain-distance-locked.js', '../point_src/collisionbox.js', '../point_src/functions/springs.js', '../point_src/velocity.js', '../point_src/setunset.js', '../point_src/stroke.js')
markdown {'html': '<hr />\n<p>In this version the pair callback method - tests for visits.</p>\n<hr />\n<p>The <code>followPoint</code> method allows a point to <em>follow</em> another point, at a distance.\nThis is a lot like constraints but with a <em>one to one</em> relationship in a single\ndirection.</p>\n<p>This <em>graph chain</em> stores those one to one relationships, with methods to iterate\nthe chain in two directions. This allows use to grab the standard <code>A -&gt; B -&gt; C</code>,\nand <code>C -&gt; B -&gt; A</code>.</p>\n<p>The graph can resolve a "star based" configuration:</p>\n<pre><code>A C\n \\ /\n B\n |\n D\n |\n E\n</code></pre>\n<p>Each connection is given in a pair, from an origin node (the <code>head</code>)</p>\n<pre><code>head = B\n\nB -&gt; C\nB -&gt; D [ -&gt; E ]\nD -&gt; E\nB -&gt; A\n</code></pre>', 'content': 'title: Graph Chain Follow Points V3\ncategories: springs\n graph\nfiles:\n head\n ../point_src/math.js\n ../point_src/extras.js\n ../point_src/point-content.js\n dragging\n pointlist\n point\n stage\n mouse\n ../point_src/graph-connections.js\n ../point_src/constrain-distance.js\n ../point_src/constrain-distance-locked.js\n ../point_src/collisionbox.js\n ../point_src/functions/springs.js\n ../point_src/velocity.js\n stroke\n\n---\n\nIn this version the pair callback method - tests for visits.\n\n---\n\nThe `followPoint` method allows a point to _follow_ another point, at a distance.\nThis is a lot like constraints but with a _one to one_ relationship in a single\ndirection.\n\nThis _graph chain_ stores those one to one relationships, with methods to iterate\nthe chain in two directions. This allows use to grab the standard `A -> B -> C`,\nand `C -> B -> A`.\n\nThe graph can resolve a "star based" configuration:\n\n A C\n \\ /\n B\n |\n D\n |\n E\n\nEach connection is given in a pair, from an origin node (the `head`)\n\n head = B\n\n B -> C\n B -> D [ -> E ]\n D -> E\n B -> A'}