This Website Lead Tracker Demo Python Game JavaScript Particle Sim C++ Embedded Design
Lead Tracker
Contact Info Certifications Resume LinkedIn

Demos▸​
4. JavaScript Particle Sim

In 2016, I got excited about a chemistry-like game where players would be encouraged to create systems to produce different molecules in increasingly efficient and creative ways. I didn't want the game to force certain physical/chemical effects, but rather for the natural evolution of the simple physics to produce interesting emergent behaviors. Unfortunately, real life is a 3-dimensional quantum computer, so I wasn't certain that a 2D Newtonian approximation could produce similar results. Thus, in order to experiment with the basic idea and see what interesting effects I could create (or, more realistically, reveal), I created the particle simulator shown here.

I would eventually become distracted by other life matters and shelve this project, hoping to return eventually to add more chemistry-like rules and create my game, but I did actually create some interesting simulations before stopping, some of which are shown below.

I decided to code this project in JavaScript because I wanted the game to eventually sit on the web, allowing anyone with a browser to enjoy without needing to download and trust an executable file. You can play with the demonstrations shown below directly through your browser, or you can download the code from GitHub here to see the code for yourself and experiment more in-depth. Note that the code comes as a Python package for easy integration with the Django Python-based web framework on which this website is built, but you can simply use the JavaScript as it is if you aren't using a Python-based web framework. Also note, I am only giving permission for personal use/experimentation but not for anything commercial.

Pool

A simple demonstration of the particle simulator that mimics an environment everyone's familiar with: pool!

Here you can easily observe how particles interact with the walls and with themselves.

Fun With Shapes

The simulator can handle any polygonal surfaces (concave or convex) and any size particles. It's especially interesting to play around with the mouse trajectory indicator here since you'll see lots of unique ricochet patterns off the central structure.

This demo also shows off emergent analogs of increasing entropy and thermal equilibrium. You can even play with gravity!

Convection

This demo shows another common thermodynamic effect known as convection, which is the process of heat transfer through the bulk movement of a gas or liquid. In the simulator, the right wall is heated, causing the particles to speed up and allowing them to fight against gravity towards the top, where they can spill over to the left, cool down on the left wall, and fall the the bottom-left corner. Particles here are low-energy, but so many of them bunch up that they eventually push into the less-dense right side again, and the circuit continues on.

Play with the controls to alter gravity and change the temperature differential to get a feel for what's really going on.

Brownian Motion

In this demo, the particle simulator reproduces an effect known as Brownian motion. This random motion was originally believed to be caused by some microscopic living organisms, but Einstein showed later in 1905 that Brownian motion was the result of otherwise undetectable atoms randomly interacting with the larger molecules, causing observable random motion. Although atoms were theorized at the time to be a possible physical reality, Einstein's work on Brownian motion proved their existence and gave the first method for experimentally determining their quantity and size.

Although the larger particles would normally travel in simple straight paths, the large quantity of smaller particles means their collisions dominate the motions of the large particles, creating haphazard meandering trajectories for the larger particles that mimic the Brownian motion described by Einstein.

Strings

Although correctly modeling covalent atomic bonds is a job for super and quantum computers, I thought I could maybe approximate their behavior and consequences by modeling a simpler spring-like bond. Eventually, I wanted to build a rule set for how these bonds are formed and broken in a way that would mimic chemistry, but for now the simulator can simply create the bonds at startup and break them once the distance between the particles gets too large.

In this demo, you can either simply watch the bonded chains fall amongst the spikes and break, or you can try to save them by disabling gravity before they fall too far.

Navigator
Table of Contents
Table of Contents