Exemplo n.º 1
0
})
n = 20
for i in range(n):
    a = -3 + 6 * (0.5 + i) / n
    line = FieldLine(field, [a * scale, 6 * scale], maxr=12, pass_dipoles=1)
    if abs((n - 1.) / 2. - i) > 7: off = 4 * [0.5]
    else: off = 4 * [0.25]
    doc.draw_line(line,
                  arrows_style={
                      'min_arrows': 2,
                      'max_arrows': 2,
                      'offsets': off,
                      'scale': 2.0
                  })
# draw the superconducting ball
ball = doc.draw_object('g', {'id': 'metal_ball'})
grad = doc.draw_object('radialGradient', {
    'id': 'metal_spot',
    'cx': '0.53',
    'cy': '0.54',
    'r': '0.55',
    'fx': '0.65',
    'fy': '0.7',
    'gradientUnits': 'objectBoundingBox'
},
                       group=ball)
for col, of in (('#fff', 0), ('#e7e7e7', 0.15), ('#ddd', 0.25), ('#aaa', 0.7),
                ('#888', 0.9), ('#666', 1)):
    doc.draw_object('stop', {'offset': of, 'stop-color': col}, group=grad)
doc.draw_object(
    'circle', {
Exemplo n.º 2
0
r = size * 1.0
exponent = 1.0 / 2.0  # run with exponent=1 to get a physically correct version

doc = FieldplotDocument('naughty-solenoid')
field = Field({'coils': [[0, 0, 0, r, l, 1]]})
n = 15
for i in range(n):
    a = (0.5 + i) / n
    a = (-1. + 2. * a)
    # ... after this, a ranges approximately from -1 to 1
    a = copysign(abs(a)**exponent, a)
    # unphysical version for pedagogical use, students explain why it's impossible
    # makes field more intense near the walls
    # re copysign, see https://stackoverflow.com/questions/1986152/why-doesnt-python-have-a-sign-function
    a = a * size
    line = FieldLine(field, [0.0, a], directions='both', maxr=15.0)
    doc.draw_line(line, arrows_style={'dist': 3, 'offsets': [0., .5, .5, 1.]})
doc.draw_object(
    'path', {
        'style': 'fill:none; stroke:#808080; ' +
        'stroke-width:.06; stroke-linecap:butt',
        'd': f'M -{l},-{r} L {l},-{r}'
    })
doc.draw_object(
    'path', {
        'style': 'fill:none; stroke:#808080; ' +
        'stroke-width:.06; stroke-linecap:butt',
        'd': f'M -{l},{r} L {l},{r}'
    })
doc.write()
Exemplo n.º 3
0
Arquivo: draw.py Projeto: dzc0d3r/lm
        line = FieldLine(field,
                         p0,
                         directions='both',
                         maxr=7,
                         path_close_tol=0.2,
                         hmax=0.1)
        doc.draw_line(line,
                      arrows_style={
                          'dist': 1.8,
                          'max_arrows': 2,
                          'offsets': [0.9, 0.3, 0.3, 0.9]
                      })
    first_sphere = False

# draw the spherical magnets
defs = doc.draw_object('defs', {})
grad = doc.draw_object('radialGradient', {
    'id': 'grad',
    'r': str(1.2 * R),
    'cx': '0',
    'cy': str(0.2 * R),
    'fx': '0',
    'fy': str(0.6 * R),
    'gradientUnits': 'userSpaceOnUse'
},
                       group=defs)
for col, of, opa in [['#ffffff', '0', '0.66'], ['#ffffff', '0.04', '0.6'],
                     ['#ffffff', '0.11', '0.4'], ['#ffffff', '0.22', '0.2'],
                     ['#555555', '0.7', '0.3'], ['#000000', '1', '0.6']]:
    stop = doc.draw_object('stop', {
        'stop-color': col,