Skip to content

Instantly share code, notes, and snippets.

@BradleyJohnson
Created January 21, 2015 16:28
Show Gist options
  • Save BradleyJohnson/eca9403c84b6129135e8 to your computer and use it in GitHub Desktop.
Save BradleyJohnson/eca9403c84b6129135e8 to your computer and use it in GitHub Desktop.
Physics(function (world) {
var viewportBounds = Physics.aabb(0, 0, window.innerWidth, window.innerHeight)
,edgeBounce
,renderer
;
renderer = Physics.renderer('canvas', {
el: 'viewport'
});
world.add(renderer);
world.on('step', function () {
world.render();
});
edgeBounce = Physics.behavior('edge-collision-detection', {
aabb: viewportBounds
,restitution: 0.99
,cof: 0.8
});
window.addEventListener('resize', function () {
viewportBounds = Physics.aabb(0, 0, renderer.width, renderer.height);
edgeBounce.setAABB(viewportBounds);
}, true);
world.add( Physics.body('circle', {
x: renderer.width / 2
,y: renderer.height / 2 - 240
,vx: -0.15
,mass: 1
,radius: 30
,styles: {
fillStyle: '#cb4b16'
,angleIndicator: '#72240d'
}
}));
world.add( Physics.body('circle', {
x: renderer.width / 2
,y: renderer.height / 2
,radius: 50
,mass: 20
,vx: 0.007
,vy: 0
,styles: {
fillStyle: '#6c71c4'
,angleIndicator: '#3b3e6b'
}
}));
var attractor = Physics.behavior('attractor', {
order: 0,
strength: .002
});
world.on({
'interact:poke': function( pos ){
world.wakeUpAll();
attractor.position( pos );
world.add( attractor );
}
,'interact:move': function( pos ){
attractor.position( pos );
}
,'interact:release': function(){
world.wakeUpAll();
world.remove( attractor );
}
});
world.add([
Physics.behavior('interactive', { el: renderer.container })
,Physics.behavior('newtonian', { strength: .5 })
,Physics.behavior('body-impulse-response')
,edgeBounce
]);
Physics.util.ticker.on(function( time ) {
world.step( time );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment