Skip to content

A cool electromagnetism simulation

Notifications You must be signed in to change notification settings

notaroomba/electromagnetism

Folders and files

NameName
Last commit message
Last commit date

Latest commit

bda3b45 · · Dec 29, 2025

History

16 Commits
Dec 29, 2025
Dec 29, 2025
Dec 29, 2025
Dec 27, 2025
Dec 27, 2025
Dec 27, 2025
Dec 29, 2025
Dec 27, 2025
Dec 27, 2025
Dec 27, 2025
Dec 29, 2025
Dec 27, 2025
Dec 27, 2025
Dec 27, 2025
Dec 27, 2025
Dec 27, 2025
Dec 27, 2025

Repository files navigation


Electromagnetism
Electromagnetism

Interactive 2D electrostatic & magnetic particle simulation with a Rust physics engine compiled to WebAssembly. ly.

Rust WASM React PixiJS

An interactive sandbox for charged particles and magnets that combines a high-performance physics core (written in Rust and compiled to WebAssembly) with a responsive web UI (React + TypeScript) and PixiJS for high-performance 2D rendering.

Live demo

Key features

  • Physics engine implemented in Rust and compiled to WebAssembly for accurate, real-time simulation
  • Charged-particle Coulomb interactions and magnet dipole approximations
  • Multiple integration methods (Euler, RK4, Verlet, Leapfrog)
  • Quadtree (Barnes–Hut) optimization for efficient Coulomb force computation
  • Interactive editor: add atoms or magnets, pause and drag objects to edit their properties
  • Side bar to configure pre-add fields and randomize them
  • Property editor for selected particles/magnets (mass, charge, magnet strength, rotation, velocity)
  • Visual overlays: equipotential / field lines, velocity vectors, trails, FPS counter
  • Magnet rendering with two-sided colors + N/S labels

Preview

Open the app locally with npm run dev and try:

  • Add charged particles and magnets from the side bar
  • Toggle velocity vectors and equipotential views from the settings bar
  • Pause, click-and-drag an object to edit it in the property editor

Building

Prerequisites

  • Rust and wasm-pack
  • Bun or Node.js

Build the physics engine (WASM)

bun run build:rust

# or
npm run build:rustt

Run the development server

bun run dev

# or
npm run devv

Build for production

bun run build

# or
npm run buildd

Notes & TODOTODO

  • Magnet physics are currently approximated using a dipole model (two pseudo-poles); more accurate magnetic interactions (Lorentz forces, torques) can be added later
  • Improve TypeScript typings for generated wasm package (currently some calls use as any)
  • More presets (e.g., dipole arrays, particle beams), and export/import of states

Credits

  • Rust + wasm-bindgen for the physics engine
  • React + TypeScript for the UI, TailwindCSS for styling, PixiJS for rendering

License

MIT


notaroomba.dev  ·  GitHub GitHub @NotARoomba

About

A cool electromagnetism simulation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published