| 623 | self.repulsion = 15 # Maximum repulsive force radius. |
| 624 | |
| 625 | def _distance(self, node1, node2): |
| 626 | # Yields a tuple with distances (dx, dy, d, d**2). |
| 627 | # Ensures that the distance is never zero (which deadlocks the animation). |
| 628 | dx = node2._x - node1._x |
| 629 | dy = node2._y - node1._y |
| 630 | d2 = dx*dx + dy*dy |
| 631 | if d2 < 0.01: |
| 632 | dx = random() * 0.1 + 0.1 |
| 633 | dy = random() * 0.1 + 0.1 |
| 634 | d2 = dx*dx + dy*dy |
| 635 | return dx, dy, sqrt(d2), d2 |
| 636 | |
| 637 | def _repulse(self, node1, node2): |
| 638 | # Updates Node.force with the repulsive force. |