Skip to the content

Karakuriからくり

Play eight native puzzles, run bounded searches, step deterministic physics and mount a canvas player controlled by pointer or keyboard.

Karakuri is the Japanese word からくり for a mechanism or ingenious device. About the name

Contents

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

NameTypeDescription
nodesRigNode[]
linksRigLink[]
staticsWorldShape[]
gravitynumber
dampingnumber

How much of its speed a node keeps each step (1 keeps all).

iterationsnumber
gripnumber

How much of a round node's speed along a surface it keeps when it touches one.

bouncenumber

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)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/karakuri 0.2.1.