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.
This software has only been built on MacOS. Building on any other platform (Windows, Linux) may be possible but will likely involve some significant modifications to the build instructions, and possibly to the makefile and other scripts.
It is possible to customize a myPhysicsLab simulation without building from source code, see Customizing myPhysicsLab Simulations.
To build from source code the required tools are
-
Closure Compiler Note that you don't need to install Maven or NPM. Just go to their Maven repository, click on the version you want, then click on the jar file to download it. myPhysicsLab compiles with closure-compiler release v20210106.
-
Closure Library is a separate download from Closure Compiler. It is a collection of JavaScript source code. You can download a zip file from their github page or use
git clone https://github.com/google/closure-library.git
.
Once the prerequisites are on your system, follow these steps:
-
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
-
Copy the file
sampleConfig.mk
tomyConfig.mk
and editmyConfig.mk
to specify location of Closure Compiler in theCLOSURE_COMPILER
variable. -
Create a symbolic link to
closure-library
in the directory that has themakefile
. Example of how to create the symbolic link:$ ln -s ../closure-library/closure/ closure-library
-
Execute
make
at the command line. (Set your directory to where themakefile
is). This will compile all applications and tests in all language versions (using the default optionCOMPILE_LEVEL=simple
). Executemake help
to see available options. -
Open the file
/build/index-en.html
with a browser. This has links to all the files that were built.
NOTE: the HTML files in the source directories cannot be used directly from a browser. You must complete the build process first.
See Building myPhysicsLab Software for more information about the build process.
See myPhysicsLab Documentation for overview of architecture and for detailed documentation of 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.
The example files are available online in two forms: advanced-compiled which loads faster and simple-compiled which allows for more customization.