Newton's law of motion
Simulation of particles based on action and reaction
2022-11-08. The simulation was programmed by Ladislav Ides, B.Sc., M.Sc., part of the script by Josh Bradley https://joshbradley.me/object-collisions-with-canvas
Simulation of particles according to the law of momentum P
m= mass
v= speed
u= speed after colision
P= m * v
m1 * v1 + m2 * v2 = m1 * u1 + m2 * u2
Learn more about particle acceleration here: https://www.xtream.sk/zakony-vesmiru
If there are multiple particles of various sizes in space, their momenta will equalize. The temperature within the substance will equalize. Therefore, larger particles will move slower, and smaller particles will move faster.
The demonstration is set up so that, at the beginning, the larger particles have the highest speed. However, very quickly after collisions, it is evident that the smaller particles accelerate from the larger ones and take part of their momentum. As a result, the speeds of the particles will arrange according to their sizes. Thus, larger particles will, on average, move slower than smaller particles. There are not as many particles as in reality, so there is a significant random factor, meaning that sometimes a particle may move outside the average speed for its size. However, the more particles added to the simulation, the more stable the results would be.
Refresh the page to better observe the acceleration of smaller particles at the beginning.
Aside from the acceleration of particles, it is also possible to observe the emergence of gravity in the simulation, which is caused by the shielding effect of the larger particles. The principle behind the emergence of gravity can be found here. The emergence of gravity is not as visible because there are few particles and the simulation is only in two dimensions, so there is a higher likelihood of particle collisions than in a 3D space. Nonetheless, you can still notice that the larger particles collide with each other and try to stay as close to each other as possible. Of course, random factors sometimes push them apart, but there is a greater likelihood that the larger particles will move toward each other. In reality, gravity is created by much smaller particles, which are far more numerous and move at higher speeds, so turbulence does not occur, and larger particles are more stable. This results in a certain frequency of their contact. The closer we push larger particles together, the more strongly they will also rebound from each other. So everything depends on a certain frequency and impact force. Meanwhile, the walls act as a screen, so larger particles often tend to collide with the walls as well.
The simulation may be inaccurate, and over time the particles may speed up or slow down. This is due to the fact that everything is based on calculations that are not perfectly accurate.
Gravity can be simulated in a similar way, but many more particles need to be simulated to reduce the random impact of larger particles.
The force of gravity, that is, the mutual attraction of particles caused by the differing sizes of the particles, always occurs during collisions between all types of particles. However, its effect depends on the density and the size differences between the various types of particles. It is possible to simulate this and thus create a miniature model of the universe without having to program anything more into the model than the action and reaction of particles. The only problem is that it is mathematically impossible to calculate particle collisions with perfect precision, as the calculations involve rounding values.
When observing the movement of particles, it looks like cellular activity. This suggests that with such a number of combinations over an infinite time, the emergence of cells and therefore life is inevitable.
HTML code for display:
<script type="text/javascript">sem vložíte zdrojový kód</script> <body onload="draw();"> <canvas id="canvas" width="600" height="600"></canvas> </body> |
Source code of the simulation:
//pohyb castic simulacia graviacie 600x600 update(time) {
/**
add(vector) {
subtract(vector) {
multiply(scalar) {
dotProduct(vector) {
get magnitude() {
get direction() { //ctx = document.getElementById('canvas').getContext('2d');
class Canvas {
sync(state) { clearDisplay() {
// opacity controls the trail effect set to 1 to remove
drawActors(actors) {
drawCircle(actor) {
class Ball { update(state, time, updateId) {
/**
/**
/**
if (distance <= this.radius + actor.radius) {
//check if hitting left or right of container
// check if hitting top or bottom of container
//if (this.position.y <= lowerLimit.y) {//moje
const newX = Math.max(Math.min(this.position.x + this.velocity.x, upperLimit.x), lowerLimit.x);
return new Ball({
get area() {
get sphereArea() {
// see elastic collision: https://en.wikipedia.org/wiki/Elastic_collision
// add mass to the system
const isMovingTowards = (particle1, particle2) => {
const runAnimation = animation => {
// return false from animation to stop
const random = (max = 9, min = 0) => { const colors = ['red', 'green', 'blue', 'purple', 'orange'];
const collidingBalls = ({ width = 600, height = 600, parent = document.body, count = 10 } = {}) => {
for (let i = 0; i < 2; i++) {
function draw() {
|