User:Andre Castro/python-svg: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 3: Line 3:
=== Experimenting with animation through svg and python ===  
=== Experimenting with animation through svg and python ===  
[http://pzwart3.wdka.hro.nl/mediawiki/images/1/1c/Andre-bars-01.svg svg animation: bars rotating in a wave]
[http://pzwart3.wdka.hro.nl/mediawiki/images/1/1c/Andre-bars-01.svg svg animation: bars rotating in a wave]
<source lang=python>
import random
print """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:cc="http://creativecommons.org/ns#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
 
  id="svg3617"
  version="1.1"
  inkscape:version="0.48.1 r9760"
  sodipodi:docname="2figures-ink.svg">
  <defs
    id="defs3619" />
  <sodipodi:namedview
    id="base"
    pagecolor="#ffffff"
    bordercolor="#666666"
    borderopacity="1.0"
    inkscape:pageopacity="0.0"
    inkscape:pageshadow="2"
    inkscape:zoom="0.35"
    inkscape:cx="416.74161"
    inkscape:cy="862.85714"
    inkscape:document-units="px"
    inkscape:current-layer="layer4"
    showgrid="false"
    inkscape:window-width="964"
    inkscape:window-height="581"
    inkscape:window-x="58"
    inkscape:window-y="0"
    inkscape:window-maximized="1"
    showborder="false"
    inkscape:showpageshadow="false" />
  <metadata
    id="metadata3622">
    <rdf:RDF>
      <cc:Work
        rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
          rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
    inkscape:label="Layer 1"
    inkscape:groupmode="layer"
    id="layer1">"""
rect = """<rect
      style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
      id="rect3625"
      width="{0}"
      height="10"
      x="{1}"
      y="{2}" >
<animateTransform attributeName="transform" begin="1" dur="{5}" type="rotate" from="360 {3} {4}" to="0 {3} {4}" repeatCount="indefinite" id="animateTransform8537" />
</rect>
"""
r=range(40)
length = len(r)
for x in r:
    x_offset=0
    overlap = 10
    width = 40+overlap
    list_times = [1, 1+x, length-x, random.randint(1,length)]
    dur_inc = 1 + x + float(0.5)
    print rect.format(width, (x_offset +(x * width)), 200, (x_offset +(x * width)), 200, dur_inc )
#how can the rectangles rotate around their center????
print """</g>
</svg>"""
</python>

Revision as of 15:50, 26 October 2011

Looking into examples - python + svg [1]

Experimenting with animation through svg and python

svg animation: bars rotating in a wave

<source lang=python> import random print """<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<svg

  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:cc="http://creativecommons.org/ns#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
 
  id="svg3617"
  version="1.1"
  inkscape:version="0.48.1 r9760"
  sodipodi:docname="2figures-ink.svg">
 <defs
    id="defs3619" />
 <sodipodi:namedview
    id="base"
    pagecolor="#ffffff"
    bordercolor="#666666"
    borderopacity="1.0"
    inkscape:pageopacity="0.0"
    inkscape:pageshadow="2"
    inkscape:zoom="0.35"
    inkscape:cx="416.74161"
    inkscape:cy="862.85714"
    inkscape:document-units="px"
    inkscape:current-layer="layer4"
    showgrid="false"
    inkscape:window-width="964"
    inkscape:window-height="581"
    inkscape:window-x="58"
    inkscape:window-y="0"
    inkscape:window-maximized="1"
    showborder="false"
    inkscape:showpageshadow="false" />
 <metadata
    id="metadata3622">
   <rdf:RDF>
     <cc:Work
        rdf:about="">
       <dc:format>image/svg+xml</dc:format>
       <dc:type
          rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
       <dc:title></dc:title>
     </cc:Work>
   </rdf:RDF>
 </metadata>
 <g
    inkscape:label="Layer 1"
    inkscape:groupmode="layer"
    id="layer1">"""

rect = """<rect

      style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
      id="rect3625"
      width="{0}"
      height="10"	
      x="{1}"
      y="{2}" >

<animateTransform attributeName="transform" begin="1" dur="{5}" type="rotate" from="360 {3} {4}" to="0 {3} {4}" repeatCount="indefinite" id="animateTransform8537" /> </rect> """

r=range(40) length = len(r) for x in r:

   x_offset=0
   overlap = 10
   width = 40+overlap
   list_times = [1, 1+x, length-x, random.randint(1,length)]
   dur_inc = 1 + x + float(0.5)
   print rect.format(width, (x_offset +(x * width)), 200, (x_offset +(x * width)), 200, dur_inc ) 
  1. how can the rectangles rotate around their center????

print """</g> </svg>""" </python>