Skip to content

2nPlusOne/matterjs-play

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matter.js Experiments Netlify Status

A handful of playful experiments with Matter.js

Setup

  1. Clone this repo
  2. Open a terminal session in the root directory
  3. Start the server: python -m http.server (or other similar command)
  4. Open localhost:8000 in your browser
  5. Have fun!

Experiments

Slice

Slice a body in two by clicking and dragging. The slice is made by partitioning the body with PolyK and converting the resulting vertex arrays into Matter.js bodies. Additional realism is achieved through the conservation of momentum and tangential velocities. The dot product is used to apply force when you slice a body upwards. See how long you can keep a piece in the air! Slice

Carve (WIP)

This experiment will allow you to carve a body by clicking and dragging. While the carving mechanic is incomplete, you can still create laser light shows with the mouse! Carve

Planets

Watch the formation of a 2D planetary system! This experiment utilizes the matter-attractors plugin to simulate gravity between bodies. The simulation is initialized with 3000 randomized orbital velocities and masses. The radius of each body has been scaled up to make the systems more visually appealing. Bodies that touch are merged at their barycenter, with their mass and velocity conserved. Performance is improved by only considering the gravitational effect of the sun on each body since the relative mass of the other bodies is negligible. Planets

Boids

Enjoy flocks of bird-like agents (boids) that exhibit emergent behavior using three simple rules: alignment, cohesion, and separation. Alignment steers boids towards the average heading of their neighbors. Cohesion steers boids towards the average position of their neighbors. Separation steers boids away from their neighbors to avoid crowding. The boids will gently swerve away from the mouse to avoid it. The matter-wrap plugin is used to wrap the boids around the screen. Screen wrapping is disabled by default in favor of the boids redirecting themselves at the edges of the screen, resulting in more interesting behavior.

The boids algorithm was first developed by Craig Reynolds in 1986, detailed further in his paper presented at SIGGRAPH'87. While there are many online resources about boids, I found this lab published by the Cornell Department of Electrical and Computer Engineering especially helpful in understanding the algorithm and tuning its parameters. Boids