myPhysicsLab provides JavaScript classes to build real-time interactive animated physics simulations.
The myPhysicsLab website shows the simulations running and contains explanations of the math behind them.
myPhysicsLab is provided as open source software under the
Apache 2.0 License. See the accompanying
file named LICENSE
. The author is Erik Neumann [email protected].
Source code is available at https://github.com/myphysicslab/myphysicslab.
It is possible to customize a myPhysicsLab simulation without building from source code, see Customizing myPhysicsLab Simulations.
To build from source code:
-
Download the myPhysicsLab source code from https://github.com/myphysicslab/myphysicslab. You can download a zip file from that github page, or use
git clone https://github.com/myphysicslab/myphysicslab.git
-
Install the required tools:
-
TypeScript You should be able to execute
tsc --version
within themyphysicslab
directory. Making an alias in your.bash_profile
like this might be helpful:alias tsc=~/Documents/Programming/myphysicslab/node_modules/typescript/bin/tsc
-
esbuild Make a symbolic link to the
esbuild
executable within themyphysicslab
directory.ln -s node_modules/esbuild/bin/esbuild esbuild
You should then be able to execute
./esbuild --version
within themyphysicslab
directory
-
-
Execute
tsc
at the command line. This will compile all the typescript.ts
files to become JavaScript.js
files in thebuild
directory. -
Execute
make
at the command line. This creates.html
files and bundled.js
files in thebuild
directory for all applications and tests in all language versions. Executemake help
to see available options. -
Open the file
/build/index-en.html
with a browser. This has links to all the example files that were built.
See Building myPhysicsLab Software for more information about the build process.
Here are some hints about installing tools, this was on MacOS. Following
this page
I used HomeBrew
to install node
, and then used node's npm
to install the other
tools locally inside the myphysicslab directory:
cd myphysicslab
npm install typescript
npm install esbuild
Those commands create some directories and files (for example node_modules
) inside
the myphysicslab directory that are unrelated to the myphysicslab project. The
.gitignore
file contains entries to prevent these from being added to the
myphysicslab project.
Test whether your installation is ready to build myphysicslab:
cd myphysicslab
tsc --version
./esbuild --version
perl --version
make --version
See myPhysicsLab Documentation for overview of architecture and for detailed documentation of software.
Building the documentation requires some additional tools, see Building myPhysicsLab Software
There are around 50 different simulations in the source code, each of which has has an example file which is mainly for development and testing. Find them in the examples index.
myPhysicsLab was started in 2001 using Java. From 2013 to 2016 the code was converted to JavaScript that depended on Google Closure Compiler.
In 2023 the code was converted to TypeScript for a couple of reasons: to be able to generate documentation, and because Google Closure Library is being retired.
Because of how modules work in TypeScript, sometimes several classes or interfaces
are combined into a single file. For example the file util/Observe.ts
contains what
was previously in 10 separate files. This can make finding things a little harder
in the new scheme.