delay it fps
Canvas is matched to your browser window. -1 ≤ x,y ≤ 1.

Now it is similar to 2D wave equation.

2D Yee's algorithm

Maxwell's equations are
    ε ∂t E = rot H,
    ∂t H = - rot E
.
Assuming that all partial derivatives of the fields with respect to z are equal to zero, we get two independant modes:
    the transverse magnetic (TM) mode with Ez , Hx , Hy field components;
    the transverse electric (TE) mode with Hz , Ex , Ey field components.
For the TM mode Maxwell's equations are reduced to
    ε ∂t Ez = ∂x Hy - ∂y Hx ,
    ∂t Hx = - ∂y Ez ,
    ∂t Hy = ∂x Ez
.
Discretization of the simulation domain for the TM polarisation is shown below.

(Ez )i-1, j+1   —   (Hy )i-½, j+1   —   (Ez )i, j+1   —   (Hy )i+½, j+1   —   (Ez )i+1, j+1
    |
(Hx )i-1, j+½
    |
    |
(Hx )i, j+½
    |
    |
(Hx )i+1, j+½
    |
(Ez )i-1, j (Hy )i-½, j (Ez )i, j (Hy )i+½, j (Ez )i+1, j
    |
(Hx )i-1, j-½
    |
    |
(Hx )i, j-½
    |
    |
(Hx )i+1, j-½
    |
(Ez )i-1, j-1 (Hy )i-½, j-1 (Ez )i, j-1 (Hy )i+½, j-1 (Ez )i+1, j-1

Three field components (Hx )i, j+½ , (Hy )i+½, j , (Ez )i, j are placed in the same Float32 texel (Hx, Hy, Ez, 0). Therefore the finite-difference expressions for field components are
    (Hy )x,y = (Hy )x,y + [(Ez )x+d,y - (Ez )x,y ]dt/dx,
    (Hx )x,y = (Hx )x,y + [(Ez )x,y - (Ez )x,y+d ]dt/dx,
    (Ez )x,y = (Ez )x,y + [(Hx )x,y-d - (Hx )x,y + (Hy )x,y - (Hy )x-d,y ]dt/dx.


Electromagnetic wave simulation
updated 7 Apr 2014