()
| 123 | } |
| 124 | |
| 125 | update() { |
| 126 | Matter.World.remove(engine.world, this.springs) |
| 127 | this.springs = [] |
| 128 | const bins = this.binnedNodes() |
| 129 | for (const node of this.nodes) { |
| 130 | const binsToCheck = this.adjacentBins(node) |
| 131 | for (const bin of binsToCheck) { |
| 132 | const key = this.binKey(bin) |
| 133 | if (!bins[key]) continue |
| 134 | for (const other of bins[key]) { |
| 135 | if (other === node) continue |
| 136 | this.springs.push(Matter.Constraint.create({ |
| 137 | bodyA: node, |
| 138 | pointA: { x: 0, y: 0 }, |
| 139 | bodyB: other, |
| 140 | pointB: { x: 0, y: 0 }, |
| 141 | stiffness: map( |
| 142 | Math.hypot(node.position.x - other.position.x, node.position.y - other.position.y), |
| 143 | 0, 12*BLOB_NODE_SIZE, |
| 144 | 0.02, 0.03, |
| 145 | true |
| 146 | ), |
| 147 | damping: 0.001, |
| 148 | // length: 0, |
| 149 | length: max( |
| 150 | 2 * BLOB_NODE_SIZE, |
| 151 | Math.hypot(node.position.x - other.position.x, node.position.y - other.position.y) * 0.975 |
| 152 | ), |
| 153 | })) |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | Matter.World.add(engine.world, this.springs) |
| 158 | } |
| 159 | |
| 160 | drawBlob() { |
| 161 | const minX = Math.min(...this.nodes.map((n) => n.position.x)) - 4 * BLOB_NODE_SIZE |
no test coverage detected