beltoforion/Educational-Javascripts-Typescript
حول
Typescript code for illustrating mathematical, physical and astromonical problems. The applets provided here are used on my webpage for educational purposes.
التعلّم والتعليمالنمو المقاس للنجوم
- خلال 24 ساعة
- ٠
- خلال 7 أيام
- ٠
- خلال 15 يومًا
- ٠
- خلال شهر
- +١
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلEducational JavaScripts (TypeScript versions)
Source code of the educational applets used on beltoforion.de.
Every applet has a demo page that runs straight from disk: open index.html in the
main folder for an overview, or the index.html inside an applet's folder.
Applets
| Folder | What it shows | Article | Build |
|---|---|---|---|
applets/doppler-effect |
Doppler effect of a moving light source | Radial velocity method | none |
applets/exoplanet-atlas |
Atlas of all known exoplanets (atlas.html) and the mass/period diagram (index.html) |
Atlas of Exoplanets, History | none |
applets/exoplanet-microlensing |
Finding planets by gravitational microlensing (schematic, exaggerated) | Microlensing | none |
applets/exoplanet-pulsar-timing |
Finding planets by pulsar timing | Pulsar Timing | none |
applets/exoplanet-radial-velocity |
Finding planets by the radial velocity of their star | Radial Velocity Method | none |
applets/exoplanet-transit |
Finding planets by transits | Transit Method | none |
applets/game-of-life |
John Conway's Game of Life | Conway's Game of Life | TypeScript |
applets/harmonic-oscillator |
Analytic solution of the damped harmonic oscillator | Damped Harmonic Oscillator | TypeScript |
applets/little-boy |
Chain reaction in the gun-type atomic bomb "Little Boy": about 8000 atoms, neutron paths, 3D model (WebGL2) | Simulating a nuclear chain reaction | none |
applets/lunar-laser-ranging |
Earth and Moon to scale, with laser pulses travelling between them in real time | – | none |
applets/magnetic-pendulum |
Basins of attraction of a pendulum over magnets | The Magnetic Pendulum | none |
applets/planetary-disk |
Dust disk around the Sun with Lagrange points and Trojans | – | none |
applets/protoplanetary-disk |
A cloud of gas and dust settles into a disk and forms protoplanets (WebGL2) | – | none |
applets/retroreflector |
How a retroreflector returns light to its source, compared with a flat mirror | – | none |
applets/simulated-evolution |
Microbes evolving their movement patterns | Simulating Evolution | none |
applets/tidal-acceleration |
Tides from free fall: the difference in the Moon's pull, with Earth held, falling or orbiting | – | none |
applets/tidal-friction |
How tides slow Earth's rotation and push the Moon outward | Tides: simulation | none |
applets/tidal-rhythmites |
Sand and mud accumulating during flood, ebb and slack water in an animated tidal cross-section | Mond auf Abwegen (DE) | Node.js (bundle) |
applets/tides |
Tidal forces of Moon and Sun | Tides Explained | webpack |
applets/wator |
Wa-Tor predator-prey simulation | World of Wator | none |
Layout
index.html overview with a link to every demo page
applets/<name>/ one folder per applet, always the version in use
originals/<name>/ earlier hand-written versions that have been replaced
shared/ code used by several applets
demo/ stand-in for the website's page environment (applet.js, applet.css)
exo-kit/ common look and controls of the exoplanet applets (canvas shell, chart, sprites)
third-party/ libraries by others (Phaser CE 2.14.0, Flotr2)
Conventions:
- The applet is the unit of order, not the technology it is built with.
applets/<name>always holds the current version. When an applet is rewritten, the previous version moves tooriginals/<name>and the new one takes its place. - Folder names and new file names use hyphens. Script files keep the names under
which the website includes them (for example
MagPendGPU.js,exoplanet_transit.js). - Every applet folder has exactly one demo page named
index.html. The demo pages are written in German. originals/holds the TypeScript versions of the magnetic pendulum, the simulated evolution and the four older exoplanet applets (Doppler effect, pulsar timing, radial velocity, transit), which were built with Phaser. The original Wa-Tor was a C++ program and lives in its own repository.
Running
No web server and no build are needed to try the applets: the compiled JavaScript is checked in. Open the main folder in Visual Studio Code, pick an applet in the Run and Debug list and press F5, or open the HTML file in a browser.
Building
Rebuild the TypeScript applets after changing a .ts file.
npm install # once, installs TypeScript 4.9
npm run build # all TypeScript applets
npm run build:game-of-life
The tides applet is bundled with webpack and has its own dependencies:
cd applets/tides
npm install
npm run build
TypeScript is pinned to 4.9 because the applets target ES5 and use the type
definitions of Phaser 2, which newer compilers no longer accept. The common compiler
settings are in tsconfig.base.json; each applet's tsconfig.json only lists its
deviations.
The protoplanetary disk is developed in a separate working folder and copied here
as a whole; change it there, not in this repository. It needs WebGL2 with
EXT_color_buffer_float. Gravity is summed directly over all pairs, so the cost grows
with the square of the particle count; ?n=<count> picks the count (64 to 65 536).
The scripts in js/ are plain scripts under the global namespace Disk, loaded in a
fixed order by index.html: experiment.js bundles the core (initial cloud,
simulation.js with the leapfrog step and merging, the clock in sim-driver.js,
diagnostics.js) without any dependency on page, camera or picture; renderer.js,
hud.js and the chart files draw, and only controls.js and main.js know the page's
element ids. The simulation runs as fast as the GPU allows, independent of the frame
rate. headless.html?n=4096&seed=22&steps=2000 computes without a picture and prints
the result as JSON (also with chromium --headless --dump-dom). In the console, sim
gives access for experiments (sim.reset(seed), sim.step(n), sim.diagnose(),
sim.checksum(), sim.pauseAtStep(n)). Different browsers may give slightly different
numbers for the same cloud; within one browser a run is repeatable.
The five applets on the exoplanet detection methods (Doppler effect, microlensing, pulsar
timing, radial velocity, transit) share one look and one way of handling. What they have
in common lives in shared/exo-kit: the canvas with its control bar and frame loop
(shell.js), the chart, the drawing helpers for labels and arrows, the observatory
backdrop and the sprite images (one copy in shared/exo-kit/assets/sprites). Each applet
is a set of plain scripts under its own global namespace (Doppler, Microlensing,
PulsarTiming, RadialVelocity, Transit) with the same interface:
<Namespace>.mount(element, { lang: 'de' | 'en' }) starts it and returns
{ setPaused, seek, destroy }; embed.html?lang=en is a bare page for an iframe. All of
them are schematics, deliberately not to scale. npm test runs the checks of their models.
The retroreflector, lunar laser ranging and tidal friction demos use the style of the
“Mond auf Abwegen” article. To embed that style, open the applet's embed.html?stil=artikel
(or embed.html?stil=artikel&lang=en for English). The shared styles and offline fonts are
in shared/mond-applets. The fonts use the
Apache 2.0 license.
The tidal rhythmites applet has two single-file distributions. Copy
index.html to open the simulation offline or use it in an iframe.
To mount it in an existing article, copy only tidal-rhythmites.js.
The widget includes its styles and draws its graphics locally.
<div id="rhythmites"></div>
<script src="tidal-rhythmites.js"></script>
<script>
const applet = TidalRhythmites.mount(document.getElementById('rhythmites'), { lang: 'de' });
</script>
The returned instance provides setPaused(on), seek(timeInCycles) and destroy().
After editing the applet scripts, CSS or embed.html template, regenerate both files with
npm run build:tidal-rhythmites.
The tidal friction applet (applets/tidal-friction, namespace TidalFriction) is built on the
same kit, which gained square buttons with a picture or sign lying on the drawing (Shell.addIconChoice,
Shell.addIconToggle), a short message on the drawing (Shell.toast) and the option to put
the pause button on the drawing (pauseInDrawing) for it, and a slider (Shell.addSlider) that
can lie on the drawing as well, a fullscreen button (fullscreen) and a small version number at
the end of the control bar (version). The kit also offers a row of text buttons
(Shell.addChoice), which no applet uses at present. Its drawing is 16:9, with the scene on the
left and the chart beside it. Its Earth is not a point mass but a mesh of 197 point masses on
rings, of uniform density, joined by springs with dampers (js/mesh.js, js/tidal-model.js).
Moon and every mesh point attract each other.
The tidal bulge, its angle to the Moon, the braking of Earth's rotation and the push on the
Moon are not drawn in but come out of that calculation (js/diagnostics.js reads them off).
Momentum and angular momentum are conserved to rounding error, which the tests check. The
camera sits above the common center of mass, Earth or the Moon and, chosen separately, does
not rotate, rotates with the Earth–Moon system or with Earth (two groups of buttons in the scene). Beneath the mesh lies a picture of the
real Earth as seen from above the orbital plane (js/globe.js): because Earth's axis is tilted by
23.5°, the north pole sits off the center of the disc and the continents turn around it. A starry sky behind the scene (js/sky.js) shows how the camera
turns: the stars are points while it rests and draw trails while it rotates. mount
returns { setPaused, setSpin, restart, destroy }.
The retroreflector applet (applets/retroreflector, namespace Retroreflector) uses the same kit
and the same 16:9 layout; mirror and retroreflector can be turned with the mouse (js/tilt-input.js).
A telescope sends a bundle of laser rays to a flat mirror and to a retroreflector (two mirrors at
right angles, the cross-section of a corner-cube prism), both of which swing back and forth. The
paths come from ray tracing on mirror segments (js/optics.js), and the chart of returned light
over tilt counts the rays that hit the telescope again (js/reflector-model.js). mount returns
{ setPaused, setTilt, destroy }.
The Little Boy applet (applets/little-boy, namespace LittleBoy) is a port of the Unity project
beltoforion/LittleBoy. All dimensions, colors and rules come
from the Unity scene and scripts and live in js/config.js; since version 1.3.0 the projectile is slimmer
(projectile to target 60 : 40 by mass, as in Little Boy), the atoms are denser and, since 1.4.0, spread
evenly in space (golden-angle spirals on cylindrical shells) instead of being cut from a cubic lattice, and
smaller so that each part alone stays subcritical, because with the original numbers the
bomb mostly fizzled; since 1.10.0 there are about 8000 atoms instead of about 2000. The calculation
(js/simulation.js) runs in fixed steps of 0.02 s, Unity's physics step: neutron paths are capsules tested
against atom spheres, found through a uniform search grid per cylinder (js/atom-grid.js). A small chart
shows the share of decayed atoms over time (js/decay-chart.js), and the parts can be labelled with leader
lines (js/part-labels.js). The
picture is drawn by a small WebGL 2 renderer (js/renderer.js, js/shaders.js) that reproduces Unity's
Standard shader. The bomb casing is a third-party model under CC BY 4.0, see
applets/little-boy/CREDITS.md; tools/convert-casing.mjs turns the
downloaded GLB file into js/casing-mesh.js. mount returns { fire, reset, setPaused, destroy }.
The lunar laser ranging applet (applets/lunar-laser-ranging, namespace LunarLaserRanging) shows
Earth, Moon and their mean distance to scale and lets short green laser pulses run between them at
the speed of light (js/pulse-train.js): about 1.26 s one way, surface to surface. Only the length
of the pulses is exaggerated. mount returns { setPaused, destroy }.
The microlensing applet shows two scenes side by side, a lens star with and without a
planet. The distorted images are computed from the lens equation (js/lens-system.js,
js/sky-raster.js), and the light curve is their summed brightness
(js/image-brightness.js). The drawn light rays are traced step by step through the
gravitational field of star and planet (js/ray-tracer.js).
Every button in the atlas title bar stands for a view. A view fills up to three panels: settings
on the left (optional), the work area in the middle, text and information on the right (see
"Ansichten der Titelzeile" in applets/exoplanet-atlas/atlas/atlas.js). The four filter sets
are views of the chart; "Entdeckungsmethoden" (detection methods) is a view of its own that
runs a method applet in the middle and lists the four applets as tiles on the right. It is
registered by applets/exoplanet-atlas/atlas/methods.js through window.ExoAtlasPages.
The applet scripts are loaded on demand from
the applet folders; where they are is set by the atlas option methods.
The exoplanet atlas has its own maintenance scripts (update-data.js,
atlas/update-index.js); see the comments at the top of applets/exoplanet-atlas/atlas.html.
License
MIT, see LICENSE. The libraries in third-party/ are under their own
licenses (Phaser CE: MIT, see third-party/phaser/license.txt; Flotr2: MIT).
The world map in applets/tidal-friction/js/earth-map.js is not MIT: it is "The Blue Marble:
Land Surface, Ocean Color and Sea Ice" by NASA Goddard Space Flight Center (Reto Stöckli,
Robert Simmon; visibleearth.nasa.gov, no. 57730), taken from
Wikimedia Commons, where it is
listed as CC BY-SA 3.0, and scaled down. Pages that embed the applet have to carry this credit.
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…