An interactive 2D electric field simulator that runs in the browser. Add point charges, drag them around, and watch the electric field lines and equipotential curves update in real time.
- Add and remove integer-valued point charges (in μC)
- Drag charges around the canvas
- Visualize electric field lines from each charge
- Visualize equipotential curves
- Zoom in/out and pan the viewport
- Real-time tooltip showing E, V, and position at the cursor
- Values displayed with SI prefixes (kN/C, MV, etc.)
The electric field at a point due to a charge
With multiple charges, the total field is the sum of each contribution (superposition):
In component form:
where
The scalar potential is:
Equipotential curves are the lines where
Electric charge is quantized. Only integer values are accepted:
The simulation maps pixel coordinates to real physical units:
| Parameter | Value | Description |
|---|---|---|
| Length | 1 px = 1 cm = |
Pixel to meter conversion |
| Charge | 1 unit = 1 μC = |
User-entered integer |
| Coulomb's constant |
|
Vacuum |
Example: A charge of 1 μC at 100 px (= 1 m) away:
Values are displayed with SI prefixes for readability:
| Prefix | Symbol | Factor |
|---|---|---|
| Tera | T | |
| Giga | G | |
| Mega | M | |
| Kilo | k | |
| Milli | m | |
| Micro | μ |
16 field lines are launched from each charge at equal angles. Each line is traced step by step:
- Compute
$\vec{E}$ at the current point - Step
4 pxin the direction of the unit field vector - Lines flow outward from positive charges and inward to negative charges
- Stop when leaving the visible area or reaching another charge
Line color maps to field strength on a log scale — blue for weak, yellow/red for strong.
The visible area is divided into a 10 px grid. The potential is computed at each corner. The Marching Squares algorithm then extracts contour lines at fixed potential levels.
Levels are spaced logarithmically (5 per sign):
- Red curves — positive potential
- Blue curves — negative potential
| Action | How |
|---|---|
| Add charge | Enter a value and click Add Charge |
| Delete charge | Select a charge, then press Delete or Backspace |
| Drag charge | Enable Draggable, then click and drag a charge |
| Zoom in/out | Mouse scroll wheel (0.2× – 5×, toward cursor) |
| Pan | Alt + left drag, or middle mouse drag |
| Show field lines | Show Field checkbox |
| Show equipotential curves | Show Potential checkbox |
| Show grid | Show Grid checkbox |
electric-sim/
├── index.html # HTML layout and control panel
├── css/
│ └── styles.css # All styles
└── js/
├── main.js # Render loop and canvas setup
├── camera.js # Zoom and pan camera system
├── controls.js # GUI events, charge management, dragging
├── physics.js # Electric field and potential calculations
└── renderer.js # Grid, charges, field lines, equipotential curves
This project uses ES Modules and cannot be opened directly as a file:// URL. You need a local server:
npx serve .
# or
python3 -m http.server 8000Then open http://localhost:8000 in your browser.

