Skip to content

Commit

Permalink
pylint of dipole
Browse files Browse the repository at this point in the history
  • Loading branch information
GadgetSteve committed Dec 2, 2015
1 parent 000e30b commit b730e68
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions site-packages/visual/examples/dipole.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
from visual import *

print("""
#!/usr/bin/env python
#coding:utf-8
"""
Click to plot a normalized electric field vector.
Vectors are blue if low magnitude, red if high.
Right button drag or Ctrl-drag to rotate camera to view scene.
Middle button drag or Alt-drag to zoom in or out.
On a two-button mouse, middle is left + right.
""")
"""
from __future__ import print_function, division

#from visual import *
import visual as vp
print(__doc__)

ec = 1.6e-19 # electron charge
EC = 1.6e-19 # electron charge

scene.title="Electric Field Vectors"
scene.range = 2e-13
vp.scene.title = "Electric Field Vectors"
vp.scene.range = 2e-13

charges = [ sphere( pos = (-1e-13,0,0), Q = ec, color=color.red, radius = 6e-15 ),
sphere( pos = ( 1e-13,0,0), Q = -ec, color=color.blue, radius = 6e-15 ),
]
CHARGES = [
vp.sphere(pos=(-1e-13, 0, 0), Q=EC, color=vp.color.red, radius=6e-15),
vp.sphere(pos=(1e-13, 0, 0), Q=-EC, color=vp.color.blue, radius=6e-15),
]

def getfield(p):
f = vector(0,0,0)
for c in charges:
f = f + (p-c.pos) * 8.988e9 * c.Q / mag(p-c.pos)**3
return f
def getfield(posn):
""" Get the field at a given point."""
fld = vp.vector(0, 0, 0)
for chrg in CHARGES:
fld = fld + (posn-chrg.pos) * 8.988e9 * chrg.Q / vp.mag(posn-chrg.pos)**3
return fld

while True:
p = scene.mouse.getclick().pos
f = getfield(p)
m = mag(f)
red = maximum( 1-1e17/m, 0 )
blue = minimum( 1e17/m, 1 )
if red >= blue:
blue = blue/red
red = 1.0
POSN = vp.scene.mouse.getclick().pos
FLD = getfield(POSN)
MAG = vp.mag(FLD)
RED = vp.maximum(1-1e17/MAG, 0)
BLUE = vp.minimum(1e17/MAG, 1)
if RED >= BLUE:
BLUE = BLUE/RED
RED = 1.0
else:
red = red/blue
blue = 1.0
arrow( pos=p, axis=f * (4e-14/1e17),
shaftwidth = 6e-15,
color=(red,0,blue))
RED = RED/BLUE
BLUE = 1.0
vp.arrow(pos=POSN, axis=FLD * (4e-14/1e17),
shaftwidth=6e-15,
color=(RED, 0, BLUE))

0 comments on commit b730e68

Please sign in to comment.