Simon created a website to assist people using Box2D. The website features the jBox2D helper.
Link to Simon’s website: https://simon-tiger.github.io/box2d-helper/
GitHub Issue about the project: https://github.com/CodingTrain/Rainbow-Topics/issues/616
In the end, he got tired of writing all the coordinates for the terrain vertices, but he did get quite far.
Applying Box2D to translate from pixels into mm:
Several recent translations of Box2D examples (from Daniel Shiffman’s book The Nature of Code) into Codea, that is Processing (Java) into Lua. Both Box2D and Codea are physics libraries.
Revolute Joint (Windmill):
Simon adds that he didn’t actually do part 4 of the coding challenge, because part 3 is recorded after part 4.
One more thing I’d like to share from this weekend is Simon’s lecture comparing three Physics libraries: Box2D, Matter.JS and ToxicLibs. He partially borrowed the lecture from Daniel Shiffman, but added extra info and even rated the libraries:
And here are two projects involving translating from library examples. The Bridge (http://brm.io/matter-js/demo/#bridge) from Matter.JS into Box2D:
Simon came up with an idea to translate a physics visualization from the Codea app (using a language called Lua) into Processing (Java) by applying Box2D. The first two videos below show him working on that project.
As he got stuck later, Simon decided to do the same project in p5.js instead, applying Matter.js:
This turned out to be quite difficult as well: he got stuck while trying to calculate the exact coordinates for all the shapes involved in the visualization (it was supposed to resemble bricks falling down and rolling down two slopes). So what Simon did as the next step in this “exercise” was switch back to Processing and create a grid with numbered coordinates. When I asked him, why he didn’t make the same grid in p5, he answered that he just loved Processing so much. Eventually though, this grew into a different project:
Confusing as these sidesteps may seem I’m sure Simon got a lot of practice out of this.
Here is a game Simon tried translating from Lua into Processing, it’s called Brickout:
In this project Simon combined two exercises and one example from Daniel Shiffman’s Nature of Code book, Chapter 5 – Physic Libraries. The specific physics library used here is Box2D. Simon combined exercises 5.6 (Bridge) and 5.10 (Attraction Apply Force), and example 5.7 (Create a windmill) to create a motor that catapults particles towards an attractor. If the particles fly past the attractor, “bricks” can be added to the canvas by clicking the mouse – the weight of the bricks helps regulate the motor in the right direction. For this project, both gravitational attraction and global gravity force were applied:
Simon has come up with a new code of his own! It’s about gravitational attraction (particles attracted to targets or moons attracted to planets) and partially based upon the Box2D library but he wrote most of the code himself. Simon used the gravitational constant and Newton’s law of universal gravitation to build this project. The law states that every point mass (m1) attracts every single other point mass (m2) by a force (F) pointing along the line intersecting both points. The force is proportional to the product of the two masses and inversely proportional to the square of the distance between them (r):
Simon had come across this formula before in Daniel Shiffman’s tutorials and just like Daniel he changed r to d (for distance):
float strength = (G * 1 * p.mass) / (distance * distance);
Simon pushed his full code to GitHub at:
Here Simon added some new features, like pressing keys for adding new targets and particles:
Here the force is becoming stronger with more targets, Simon explains:
We’ve also got a video of Simon talking about this project in Dutch (showing it to his math teacher):