Reference · Deterministic 2D physics
addRopefunction
Lays a rope of pieces links from (ax, ay) to (bx, by): the first node is pinned and the last is the node end if
one is given (its place is moved to the rope's end), and the nodes between are light. Gives back the indices of the
rope's nodes from the pinned end to the other and of its links.
Import it
import { addRope } from "@johnmorrisdotca/karakuri/physics";
Definition
function addRope(rig: Rig, ax: number, ay: number, bx: number, by: number, pieces: number, end?: number): { nodes: number[]; links: number[]; }
Parameters
| Name | Type | Description |
|---|---|---|
rig | Rig | The mutable native rope nodes, constraints and static geometry. |
ax | number | The first segment endpoint’s horizontal coordinate. |
ay | number | The first segment endpoint’s vertical coordinate. |
bx | number | The second segment endpoint’s horizontal coordinate. |
by | number | The second segment endpoint’s vertical coordinate. |
pieces | number | The positive number of rope segments to create. |
end (optional) | number | undefined | Optional existing native node index used as the rope’s far endpoint. |
Returns
{ nodes: number[]; links: number[]; }
Lays a rope of pieces links from (ax, ay) to (bx, by): the first node is pinned and the last is the node end if one is given (its place is moved to the rope's end), and the nodes between are light. Gives back the indices of the rope's nodes from the pinned end to the other and of its links.
Examples
import { addRope, createRig, length } from "@johnmorrisdotca/karakuri/physics";
console.log(addRope(createRig({gravity:0}),0,0,10,0,2).links.length);2What it prints (run when this page was built)