Web Lattice Dynamics: atomic motion in crystals, in a browser
Preview of master
branch index.html
:
https://htmlpreview.github.io/?https://github.com/aephil/WeLD/blob/master/index.html
First, install the required npm modules:
npm install --dev
.
Make sure you have npx
installed globally (npm install -g npx
).
Run the http server with the command npm start
Unit tests for key bits of code should be put in the test
directory, for example
tests/someDirectory/testFileNumberOne.test.js
.
To run the tests, run npm test
from your terminal.
If the source code has changed since it was last transpiled,
it needs to be transpiled again before you rerun the tests.
To tranpsile, run npm run transpile
. However, npm test
automatically does this. If you know you don't need to
transpile again and want to save time, you can use npm run _test
,
which will not transpile the source code again.
IMPORTANT: When importing functions using require
in the
node environment, you must access the transpiled
directory rather
than src
. So for example, to require src/modules/physics/ForceMap.js
from tests/file.test.js
, you need the path ../transpiled/modules/physics/ForceMap
,
not ../src/transpiled/modules/physics/ForceMap
.
When running code in the browser, use ES6 module syntax, e.g.:
// src/path/to/functionDefinedHere.js
export const myFunc = function(x, y, z) {
// do stuff
}
// src/programs/iWantTheFunctionInThisFile.js
import {myFunc} from '../path/to/functionDefinedHere.js';
// Now w can use myFunc in this file
When running code in NODE, e.g. for running tests, first make
sure you have transpiled the source code since the last change to
the source code (Happens automatically if you use npm test
to run the tests),
and then use CommonJS module syntax, with
the caveat that you need to access the transpiled
directory instead
of the src
directory, e.g.:
// src/path/to/functionDefinedHere.js
export const myFunc = function(x, y, z) {
// do stuff
}
// tests/functions/testMyFunc.test.js
const myFunc = require('../../transpiled/path/to/functionDefinedHere');
// Now we can use myFunc in this file
Note that when we use the CommonJS syntax, we do not put the .js
at the end, whereas we do when we use ES6, and additionally it is important
that when using require
in node for this codebase that you access
the transpiled
directory.
The Terminal accepts commands used to modify the simulation.
- move [id:uint] [x:int] [y:int] [z:int]: Moves a node [id] to the location in the simulation
- sample [size:uint]: Changes the sample size in the plot window. A higher sample size zoom out the reading.
- probe [rate:uint]: Changes the probe rate in the plot window. The probe rate for individual nodes is rate/10.
- fps [rate:uint] Changes the framerate.