Using Physics JS
A weeks ago I for an animation project, I had to learn a new javascript library. The first library I choose was famous js, http://famous.org/. After three days learning the library through their tutorials, I found out that they had changed their libarary and the tutorials no longer applied. So…I tried another library called physics js, http://wellcaffeinated.net/PhysicsJS/. What a great library for doing animation!
For off you initiate your physics js library by initiating it with a function that has the world passed it it. The world is where you can change the physical attributes and as I did below, make the bounderies of the world the window width and height so that if you change window size, it won’t effect the app. The stylesheet that is used is CSS Canvas and physics js comes with its own built in renderer.
The physics js library also let you control behavior of objects (objects that have been created not objects in javascript) and gravity. For this app I used the Newton gravity, which physics library already does all of the math for it.
Get Anders Pederson’s stories in your inbox
Join Medium for free to get updates from this writer.
I started the program with having 3 blocks that appear and then wherever you click, another box appears. The point of this app is to build up the blocks to the top.
It can be checked out here: http://andersped.github.io/unicornBattle.





