Mote

A very small engine for tiny demos and games in the browser. The minis on this site run on it.

The word Mote under a beam of light with one speck of dust caught in it.
language
TypeScript
status
in use on this site

Mote is the small engine under every mini on this site. It holds the loop, canvas and mouse code, so each mini doesn’t have to write them again.

Drag a block to throw it. Double-click an empty spot to drop another.

What it does

  • A stage. A canvas that fits its box and stays sharp, a loop that moves in fixed steps of 1/120 of a second, the mouse, a few keys, and the page’s own colors. It only runs while you can see it, and stops when nothing is moving. It can hold the mouse inside the box for a game that is all mouse.
  • 2D physics. Boxes, balls and shapes with weight, friction and bounce; walls; pins, rods and ropes; a motor; a hand to pick things up and throw them.
  • 3D. Solids that fall, tumble and hit each other corner to corner, drawn with depth, light and shadow.
  • Tests. A pile that does not move once it has settled, friction that holds to within a degree, a chain that keeps its length, dice that land fairly.

Dependencies

None. It is about 3,000 lines of TypeScript.

For one night it used three libraries copied into its source: planck for 2D, cannon for 3D and three for drawing. They didn’t fix the physics, and the dice tower downloaded 540 KB to roll a die, so I removed them. The 2D physics, the 3D physics and the 3D drawing are Mote’s own now, and the dice tower downloads 40 KB.

The physics follows the soft step method Erin Catto described for Box2D 3. Where things touch is found once a step. The step is then taken in a few small parts, and in each part every contact is solved as a very stiff spring.

What runs on it

Everything on the minis page: a pile of blocks, a dice tower, a Plinko board that makes passwords, and a creature that learns to walk.

Using it

It is free, under the MIT license. The folder is self-contained, so copy it. A mini is one function that sets a scene up and returns how to step it and how to draw it.