This is the part that Simon successfully translated into Java:
Around minute 30 of the Attraction and Repulsion Forces Coding Challenge video Simon got stuck with his Java code. Although everything seemed right, his particle didn’t trace nice patterns but went off the screen. Simon was very upset about this, it took me a while to console him. This is where Simon got stuck:
The little particles are attracted to one another but don’t overlap. This is a simpler kind of attraction where every particle has two perception radii: a minimum and a maximum perception radius. Two particles within each other’s maximum radius are attracted to each other but repel each other once one of them enters the other’s minimum radius:
Simon placed this project in a GitHub chat and got some interesting advice (make the mouse a repulser). In the video below he changes the code, creating a repulsing element:
Simon returned to his “old” code (something he wrote about a month ago) and fixed the collision detection in it. He called this “geometry free”collision detection because he doesn’t use any geometry for this project, but only attraction behaviour. The particles repel each other when the distance between them is 20 pixels.
Here the particles are attracted to the black blobs:
The next exciting step in writing his own code about spring force: Simon actually created an interface to allow anyone to build his own shape made of springs and particles! Simon put this project on GitHub and hosted it to make it accessible online.
The code: https://github.com/simon-tiger/spring-animation-tool
The online interface to play with: https://simon-tiger.github.io/spring-animation-tool/
He also wrote the instructions himself and placed them in the GitHub Wiki: https://github.com/simon-tiger/spring-animation-tool/wiki/Intro
Videos of the project step by step:
Simon doesn’t consider this project finished. He wants to come up with a way to apply spring force to all the springs simultaneously to make sure the shape’s sides are equal in the final stage.
Simon used Chapter 3 (Oscillation) of Daniel Shiffman’s book The Nature of Code as the theoretical basis for creating his own code. First, he played around with what he calls “soft springs” – multiple spring arrays connecting multiple particles (some of them locked but most of them moving) – allowing for most interesting designs thanks to spring force.
Simon called the video below “a mess” that “doesn’t look promising”, but to me it’s my favourite pattern. To me it resembles a constructivist poster turned alive, something like an El Lissitzky animation:
Other soft springs step by step (Simon explains what soft springs are in the first video):
Simon eventually stepped over t trying to create sets of springs and particles that unfold into certain geometrical shapes, like a trapezoid here:
And finally, a hexagon:
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):
Simon loved Daniel Shiffman’s simulation of the Plinko game and added some extra features to Daniel’s code, like a button to make new chips appear. He also saw a television version of Plinko where people were trying to win money, so he added the figures below to indicate your score.
Simon put this project on GitHub, too!
Direct link to the game: https://simon-tiger.github.io/plinko/
You can also both the code and play with the animation via the p5.js web editor (hit Download to get the animation on your computer): http://alpha.editor.p5js.org/simontiger/sketches/Sk23OkW6x