fork download
  1. import svgwrite
  2. from svgwrite import cm, mm
  3.  
  4.  
  5. def basic_shapes(name):
  6. dwg = svgwrite.Drawing(filename=name, debug=True)
  7. hlines = dwg.add(dwg.g(id='hlines', stroke='green'))
  8. for y in range(20):
  9. hlines.add(dwg.line(start=(2*cm, (2+y)*cm), end=(18*cm, (2+y)*cm)))
  10. vlines = dwg.add(dwg.g(id='vline', stroke='blue'))
  11. for x in range(17):
  12. vlines.add(dwg.line(start=((2+x)*cm, 2*cm), end=((2+x)*cm, 21*cm)))
  13. shapes = dwg.add(dwg.g(id='shapes', fill='red'))
  14.  
  15. # set presentation attributes at object creation as SVG-Attributes
  16. shapes.add(dwg.circle(center=(15*cm, 8*cm), r='2.5cm', stroke='blue',
  17. stroke_width=3))
  18.  
  19. # override the 'fill' attribute of the parent group 'shapes'
  20. shapes.add(dwg.rect(insert=(5*cm, 5*cm), size=(45*mm, 45*mm),
  21. fill='blue', stroke='red', stroke_width=3))
  22.  
  23. # or set presentation attributes by helper functions of the Presentation-Mixin
  24. ellipse = shapes.add(dwg.ellipse(center=(10*cm, 15*cm), r=('5cm', '10mm')))
  25. ellipse.fill('green', opacity=0.5).stroke('black', width=5).dasharray([20, 20])
  26. dwg.save()
  27.  
  28. if __name__ == '__main__':
  29. basic_shapes('basic_shapes.svg')
  30.  
Runtime error #stdin #stdout #stderr 0.01s 28384KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
    import svgwrite
ImportError: No module named 'svgwrite'