Reference · Deterministic 2D physics
Rigtype
A set of nodes and links, with the fixed shapes the round nodes rest on.
Import it
import type { Rig } from "@johnmorrisdotca/karakuri/physics";
Definition
interface Rig {
nodes: RigNode[];
links: RigLink[];
statics: WorldShape[];
gravity: number;
damping: number;
iterations: number;
grip: number;
bounce: number;
}
Members
| Name | Type | Description |
|---|---|---|
nodes | RigNode[] | |
links | RigLink[] | |
statics | WorldShape[] | |
gravity | number | |
damping | number | How much of its speed a node keeps each step (1 keeps all). |
iterations | number | |
grip | number | How much of a round node's speed along a surface it keeps when it touches one. |
bounce | number |
Examples
import { addRope, createRig } from "@johnmorrisdotca/karakuri/physics";
import type { Rig } from "@johnmorrisdotca/karakuri/physics";
const rig=createRig({gravity:0,iterations:1});
addRope(rig,0,0,10,0,2);
const value: Rig = rig;
console.log(value);{
nodes: [
{ x: 0, y: 0, px: 0, py: 0, invMass: 0, r: 0 },
{ x: 5, y: 0, px: 5, py: 0, invMass: 1, r: 0 },
{ x: 10, y: 0, px: 10, py: 0, invMass: 1, r: 0 }
],
links: [
{ a: 0, b: 1, length: 5, alive: true },
{ a: 1, b: 2, length: 5, alive: true }
],
statics: [],
gravity: 0,
damping: 0.999,
iterations: 1,
grip: 0.9,
bounce: 0.25
}What it prints (run when this page was built)