本文へ移動

Karakuriからくり

8つの標準のパズルで遊び、探索や再現できる物理を使い、ポインターやキーボードで操作する盤を表示できます。

「からくり」は、仕組みや工夫した装置を表す言葉です。 名前について(英語)

目次

リファレンス

再現できる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.

ソースを見るGitHub で編集@johnmorrisdotca/karakuri 0.2.1 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。