from __future__ import division from visual import * scene.background = color.white scene.x = scene.y = 0 scene.width=1000 scene.height=600 print """ Ruth Chabay 2002 Single traveling pulse of radiation. Establishes what we are talking about in derivation at beginning of chapter 23. """ c = 3e8 lamb = 1e-10 h = 1e-10 omega = 2*pi*c/lamb xx = arange(-2*lamb,-2*lamb+lamb/2, lamb/20.) xhat = vector(1,0,0) Evec = [] ff = frame() z = 0 y = 0 E0 = lamb/2 case = 1 if case is 1: ##CASE 1 ## E +y, B+z for y in arange(-0.8*lamb, 0.8*lamb+lamb/300, 0.8*lamb): for x in xx: ea = arrow(pos=(x,y,z), axis=(0,E0,0), color=(1.,.6,0), shaftwidth=lamb/40., frame=ff) ba = arrow(pos=(x,y,z), axis=(0,0,E0/2), color=(0,1,1), shaftwidth=lamb/40., frame=ff) ea.B = ba Evec.append(ea) else: #### CASE 2 #### E -z, B+y for y in arange(-0.8*lamb, 0.8*lamb+lamb/300, 0.8*lamb): for x in xx: ea = arrow(pos=(x,y,z), axis=(0,0,-E0), color=(1.,.6,0), shaftwidth=lamb/40., frame=ff) ba = arrow(pos=(x,y,z), axis=(0,E0/2,0), color=(0,1,1), shaftwidth=lamb/40., frame=ff) ea.B = ba Evec.append(ea) scene.mouse.getclick() dx = vector(lamb/200,0,0) scene.autoscale=0 while 1: rate(50) for ea in Evec: ea.pos = ea.pos + dx ea.B.pos = ea.B.pos + dx