# paste this code at the end of VectorFieldPlot 3.3
import os
if not os.path.exists('anims'):
os.mkdir('anims')
frames = 50
d = 0.35 # animation amplitude
r = 7.5 # charge radius
# iterate frames
for i in range(frames):
doc = FieldplotDocument('VFPt_dipole_animation_magnetic_{0:0>2}'.format(i),
commons=True, width=220, height=220, unit=100)
a = sin(i*pi/frames) * 0.75 - 0.25 * sin(3.0 * i*pi/frames)
if a == 0.:
# pointlike dipole
field = Field([ ['dipole', {'x':0, 'y':0, 'px':1, 'py':0}] ])
else:
# magnetic dipole
field = Field([ ['ringcurrent', {'x':0, 'y':0, 'phi':0, 'R':d*a, 'I':1}] ])
doc.draw_currents(field, scale=r/14)
if d * a < r / doc.unit:
# draw dipole symbol
symb = doc.draw_object('g', {'id':'dipole_symbol',
'transform':'scale({0},{0})'.format(
sqrt(1.0/doc.unit**2-(d*a/r)**2))})
defs = doc.draw_object('defs', {}, group=symb)
spot = doc.draw_object('radialGradient', {'id':'light_spot',
'cx':'0.65', 'cy':'0.7', 'r':'0.75'}, group=defs)
for col, of in [['#fff', '0'], ['#ddd', '0.15'],
['#aaa', '0.7'], ['#444', '1']]:
doc.draw_object('stop', {'stop-color':col, 'offset':of}, group=spot)
doc.draw_object('circle', {'cx':'0', 'cy':'0', 'r':str(r),
'style':'fill:url(#light_spot); stroke:#000000; stroke-width:1'}, group=symb)
doc.draw_object('path', {'style':'fill:#000000; stroke:none',
'd':'M -4,1 H 0 V 4 L 5,0 L 0,-4 V -1 H -4 V 1 Z'}, group=symb)
V0 = field.V((0.75, 0.))
n = 20
# iterate fieldlines
for j in range(n):
t = -1.0 + 2.0 * (j + 0.5) / n
y = 0.25 * ((t-1)**-2 - (t+1)**-2) - 0.3*t
dy = (y / abs(y) * d * a) * (1.0 - t**2)
sf = None
if i > 0:
sf = [lambda p:-p[0], lambda p:p[0]]
line = FieldLine(field, [0, y + dy],
directions='both', maxr=1e4, maxn=2e4, stop_funcs=sf)
doc.draw_line(line, linewidth=1.0,
arrows_style={'scale':1.1, 'at_potentials':[-V0, 0, V0],
'condition_func':lambda xy: (fabs(xy[0]) < 1e-5 and
fabs(xy[1]) > d*a) or fabs(xy[0]) > 0.3})
doc.write(filename='anims/' + doc.name)