nago.js
Version:
nago 2D Physics Engine
25 lines • 987 B
HTML
<html>
<body>
<script src="../dist/nago.min.js"></script>
<script>
var { World, Vertex, MoveableDisc, Segment } = nago;
var world = new World();
var v0 = new Vertex({xpos: -10, ypos: 30});
var v1 = new Vertex({xpos: 10, ypos: 30});
world.vertices.push(v0);
world.vertices.push(v1);
var arc = new Segment({v0, v1});
arc.calculateNormals(); // you must run this function whenever you update this arc object.
world.segments.push(arc);
var disc = new MoveableDisc({xpos: 0, ypos: 0, radius: 5, xspeed: 0.1, yspeed: 2});
world.discs.push(disc);
// you may do this part inside a timeout, interval or requestanimationframe etc callback.
for (var i=0;i<50;i++){
// you may render the physical world on screen here any way you like.
// for illustration, we will only log some example values.
console.log(disc.pos.x, disc.pos.y, disc.speed.x, disc.speed.y);
world.advance(1);
}
</script>
</body>
</html>