File:Cylindrical magnet.svg

Summary

{{Information

|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 =2015-05-23 |source =Own work |author =Geek3 |other versions =File:VFPt cylindrical magnet.svg (with field lines) |other fields= {{Igen|Python|+|%v|c1=

  1. !/usr/bin/python
  2. -*- 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.


  1. 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.)))


  1. 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'))


  1. 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)


  1. 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)))


  1. 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.
Category:License migration redundant#Cylindrical%20magnet.svgCategory:GFDL#Cylindrical%20magnet.svg
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.
Category:CC-BY-3.0#Cylindrical%20magnet.svg
You may select the license of your choice.
Category:Self-published work
Category:Images with Python source code Category:Magnet icons Category:Green with red Category:SN letter combinations Category:Bar magnets Category:Photos by User:Geek3
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