リファレンス
再現できる2D物理
import { … } from "@johnmorrisdotca/karakuri/physics";
最小化と gzip 圧縮をしたサイズは 5.0 kB(読み込むものをすべて含み、esbuild で計測)
リファレンスの説明と例は英語です。見出しと目次は日本語です。
エクスポート
| 名前 | 種類 | 概要 |
|---|---|---|
addBody | 関数 | Adds a body to the world and gives it back. |
addLink | 関数 | Links two nodes at their present distance (or at length) and gives back the link's index. |
addNode | 関数 | Adds a node and gives back its index. |
addRope | 関数 | 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. |
Body | 型 | A rigid body. |
BodySpec | 型 | What createBody is told. |
BodyType | 型 | How a body moves: dynamic by forces and contacts, kinematic only as the game sets it (it pushes, and is not pushed), static not at all. |
capsulesAlong | 関数 | A capsule chain for a drawn line: one capsule between each pair of neighbouring points. |
CapsuleShape | 型 | A thick segment, from (ax, ay) to (bx, by) with a radius, placed in the body's own frame. |
CircleShape | 型 | A disc, placed in the body's own frame (its origin is the body's centre of mass for a dynamic body). |
clamp | 関数 | value held between low and high. |
closestBetweenSegments | 関数 | The nearest points of two segments: where on each, and how far apart they are. |
closestOnSegment | 関数 | The point on the segment a to b nearest to (px, py), and how far along the segment it is (0 to 1). |
Contact | 型 | One contact between two shapes: the normal points from a towards b. |
contactsBetween | 関数 | The contacts between two bodies whose shapes are within margin of each other. |
countOf | 関数 | How many particles of a kind. |
createBody | 関数 | Makes a body from a spec. |
createFluid | 関数 | Makes a liquid with no particles. |
createRig | 関数 | Makes an empty rig. |
createWorld | 関数 | Makes a world. |
Disc | 型 | The round bodies the particles must not enter (a character, a coin): centre and radius. |
distance | 関数 | The distance between two points. |
distanceSquared | 関数 | The squared distance between two points, which needs no square root. |
distanceToSegment | 関数 | How far (px, py) is from the segment a to b. |
fillRect | 関数 | Fills the rectangle from (x, y) to (x + w, y + h) with particles of one kind on a grid a little looser than they settle. |
Fluid | 型 | The liquid: its particles and how it behaves. |
FluidKind | 型 | What a particle is made of. |
fluidNumbers | 関数 | Every number of the liquid's particles, for hashing it (kinds as 0, 1, 2). |
gap | 関数 | The gap between two bodies: the smallest gap of any pair of their shapes (negative when they overlap). |
hashNumbers | 関数 | A 32-bit FNV-1a hash of a list of numbers, taken over the bits of each as a 64-bit float. |
isSettled | 関数 | Whether every dynamic body in the world is slower than speed (units a second) and is hardly turning. |
length | 関数 | The length of (x, y). |
linkCrossed | 関数 | The index of the first live link that the swipe from (x1, y1) to (x2, y2) crosses, or -1. |
nearestTo | 関数 | The nearest distance from a particle of a kind to a disc's surface (negative when it is inside), or Infinity when there is none. |
nodeSpeed | 関数 | The speed of a node in units a second at a step of dt. |
Particle | 型 | One particle. |
pointInPolygon | 関数 | Whether (px, py) is inside the polygon (an even-odd test over its vertices, in order). |
refreshShapes | 関数 | Recomputes a body's shapes in world places from its position and angle. |
Rig | 型 | A set of nodes and links, with the fixed shapes the round nodes rest on. |
RigLink | 型 | A link that keeps two nodes length apart (a rope pulls but does not push: slack links only pull). |
RigNode | 型 | A point of a chain. |
rigNumbers | 関数 | Every number of the rig's nodes, for hashing it. |
segmentsIntersect | 関数 | Whether the segments a1 to a2 and b1 to b2 cross or touch. |
Shape | 型 | A shape of a body. |
STEP | 定数 | The length of the fixed step every game runs at, in seconds. |
stepFluid | 関数 | Advances the liquid by one step of dt seconds. |
stepRig | 関数 | Advances the rig by one step of dt seconds. |
stepWorld | 関数 | Advances the world by one fixed step (STEP seconds) in substeps smaller ones. |
unit | 関数 | The unit vector of (x, y), or (0, 0) for a zero vector. |
Vec | 型 | A point or a vector in the plane. |
World | 型 | The world: its gravity (down is +y, in units a second squared), its bodies in the order they were added, and how hard it works. |
worldNumbers | 関数 | Every number of a world's bodies' state, for hashing it: a determinism test compares these bit for bit. |
WorldShape | 型 | A shape as the world sees it now: a circle as (ax, ay, r) with a = b, a capsule with its two ends. |
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。