Simon translated Attraction and Repulsion Forces Coding Challenge into Java


Simon translated part of the Attraction and Repulsion Forces Coding Challenge from JavaScript into Processing (Java). In the first video below he explains the formulas for attraction and repulsion forces:

This is the part that Simon successfully translated into Java:


Attraction_Repulsion 12 May 2017


Attraction_Repulsion 12 May 2017 2


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:


Polar Distribution to create clusters

Simon has written a code about using Polar Distribution to create clusters in p5.js (JavaScript). The code is available online at:

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:


Geometry Free Collision Detection. Attractors.

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:


Attractors 26 Apr 2017

Spring Animation Tool (Simon’s own code)

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:

The online interface to play with:

He also wrote the instructions himself and placed them in the GitHub Wiki:

Intro Spring Animation Tool 24 Apr 2017

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.

Soft Springs (Simon’s own code)

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:

Gravitational Attraction (World Generator in Java). Simon’s new own code!

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 (m2by 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):
F=G{\frac {m_{1}m_{2}}{r^{2}}}\

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’s Plinko


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:

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):