File:Cylindrical magnet.svg

Uploaded by Geek3
Upload date 2015-05-23T19:57:52Z
MIME type image/svg+xml
Dimensions 616 × 216 px
File size 1.6 KB

Summary

Description
English: Schematic image of a cylindrical bar magnet. Southpole colored green with letter S, Northpole colored red with letter N.
The image is created by the following python source-code. Requirements:
Date
Source Own work
Author Geek3
Other versions File:VFPt cylindrical magnet.svg (with field lines)
SVG development
InfoField
 The SVG code is valid.
 This vector image was created with Python.
 This file uses embedded text.
Source code
InfoField

Python code

#!/usr/bin/python
# -*- coding: utf8 -*-

try:
    import svgwrite as svg
except ImportError:
    print 'requires svgwrite library: http://pypi.python.org/pypi/svgwrite/'
    exit(1)


name = 'Cylindrical_magnet'
w, h = 616, 216
lw = 16
l, r = (w - lw) / 2., (h - lw) / 2.


# document
doc = svg.Drawing(name + '.svg', size=(w, h))
doc.set_desc(title=name,
    desc='about: http://commons.wikimedia.org/wiki/File:{0}.svg'.format(name))
doc['stroke'] = 'black'
doc['stroke-linejoin'] = 'miter'


magnet = doc.add(doc.g(id='magnet', transform='translate({0},{1})'.format(w/2., h/2.)))


# green and red areas
magnet.add(doc.rect(insert=(-l, -r), size=(2*l, 2*r),
    fill='#00cc00', stroke='none'))
magnet.add(doc.rect(insert=(0, -r), size=(l, 2*r),
    fill='#ff0000', stroke='none'))


# light reflection gradient overlay
grad = doc.defs.add(doc.linearGradient(id='gradient',
    x1=0, x2=0, y1=-r, y2=r, gradientUnits='userSpaceOnUse'))
for col, of, opa in [['#000000', '0', '0.125'],
    ['#ffffff', '0.07', '0.125'], ['#ffffff', '0.25', '0.5'],
    ['#ffffff', '0.6', '0.2'], ['#000000', '1', '0.33']]:
    grad.add_stop_color(offset=of, color=col, opacity=opa)


# frame
magnet.add(doc.rect(insert=(-l, -r), size=(2*l, 2*r),
    style='fill:url(#gradient); stroke-width:{0}; stroke-linejoin:miter; stroke:#000000'.format(lw)))


# S and N labels
S = doc.text('S', insert=(0, 0),
        transform='translate({0},{1}) scale({2},{2})'.format(
        -0.65 * l, 0.44 * r, r / 100.))
N = doc.text('N', insert=(0, 0),
        transform='translate({0},{1}) scale({2},{2})'.format(
        0.65 * l, 0.44 * r, r / 100.))
text_attr = {'text-anchor':'middle',
    'style':'fill:#000000; stroke:none; ' +
    'font-size:120px; font-family:Bitstream Vera Sans'}
for k, v in text_attr.iteritems():
    S[k] = v
    N[k] = v
magnet.add(S)
magnet.add(N)


doc.save()
try:
    import xml.dom.minidom
    xml = xml.dom.minidom.parse(name + '.svg')
    with open(name + '.svg', 'w') as svg_file:
        svg_file.write(xml.toprettyxml(indent='  '))
except ImportError: pass

Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
You may select the license of your choice.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

23 May 2015

image/svg+xml

d046526eb1029696901b519a6cf0b9a246cea27c

1,615 byte

216 pixel

616 pixel

Category:Bar magnets Category:CC-BY-3.0 Category:GFDL Category:Green with red Category:Images with Python source code Category:License migration redundant Category:Magnet icons Category:Photos by User:Geek3 Category:SN letter combinations Category:Self-published work Category:Valid SVG created with Python code