# paste this code at the end of VectorFieldPlot 1.2
frames = 50
d = 0.35 # animation amplitude
r = 7.5 # charge radius
# iterate frames
for i in range(frames):
doc = FieldplotDocument('VFPt_dipole_animation_electric_{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 i == 0:
# pointlike dipole
field = Field({'dipoles':[[0,0,1,0]]})
else:
# electric dipole
field = Field({'monopoles':[[-d*a,0,-0.5/(d*a)], [d*a,0,0.5/(d*a)]]})
doc.draw_charges(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)
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
line = FieldLine(field, [0, y],
directions='both', maxr=1e4, maxn=2e4)
doc.draw_line(line, linewidth=1.0,
arrows_style={'dist':1.25, 'scale':1.1, 'max_arrows':2})
doc.write(filename='anims/' + doc.name)