A simple, lightweight physics engine written in CoffeeScript
Switch branches/tags
Nothing to show
Pull request Compare This branch is 11 commits behind soulwire:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
compiled
deploy
source
CakeFile
LICENSE
README.md
index.html

README.md

Coffee Physics

A lightweight physics engine, written in CoffeeScript. Why? Why not!?

Early demos can be found here: http://soulwire.github.com/Coffee-Physics/

A Quick Example

The CoffeePhysics API is designed to be very simple. Consider the following example:

// Create a physics instance
var physics = new Physics();

// Design some behaviours for particles
var attraction = new Attraction( new Vector( 200, 200 ) );

// Allow particle collisions to make things interesting
var collision = new Collision();

for ( var i = 0; i < 1000; i++ ) {

	// Create a particle
	var particle = new Particle();

	// Make it collidable
	collision.pool.push( particle );

	// Apply behaviours
	particle.behaviours.push( attraction, collision );

	// Add to the simulation
	physics.particles.push( particle );
}

function update() {

	// Step the simulation
	physics.step();

	// Render particles
	for ( var i = 0, n = physics.particles.length; i < n; i++ ) {

		var particle = physics.particles[i];
		ctx.beginPath();
		ctx.arc( particle.x, particle.y, particle.mass * 10, 0, Math.PI * 2 );
		ctx.fill();
	}
	
	requestAnimationFrame( update );
}

// Kick it off
update();