{"id":2401,"date":"2015-05-21T00:29:33","date_gmt":"2015-05-21T00:29:33","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=2401"},"modified":"2015-05-21T00:29:33","modified_gmt":"2015-05-21T00:29:33","slug":"generate-a-sin-wave-svg-in-python","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/generate-a-sin-wave-svg-in-python\/","title":{"rendered":"Generate a sin wave svg in Python"},"content":{"rendered":"<p>To set this up, you need do install pysvg:<\/p>\n<pre>\npip install pysvg\n<\/pre>\n<p>The following sets up a sin wave svg with Python:<\/p>\n<pre lang=\"python\">\nimport pysvg.structure\nimport pysvg.builders\nimport pysvg.text\nimport math\n\nsvg_document = pysvg.structure.Svg()\n\nshape_builder = pysvg.builders.ShapeBuilder()\n\nstyle = pysvg.builders.StyleBuilder()\nstyle.setStrokeWidth(2)\nstyle.setStroke('black')\n\ndef line(a, b):\n    if (a == None):\n        return\n    if (b == None):\n        return\n    (x1, y1) = a\n    (x2, y2) = b\n    print x1\n    line = shape_builder.createLine(x1, y1, x2, y2, style)\n    svg_document.addElement(line)\n\nlines = [(0, 100), (20, 300), (0, 10), (100, 0)]\n\npre = None\nfor id in xrange(1000):\n    point = (id, 100.0 + 100.0 * math.sin(id\/20.0))\n    line(point, pre)\n    pre = point\n    \nprint(svg_document.getXML())\n\nsvg_document.save(\"Documents\/test-pysvg.svg\")\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To set this up, you need do install pysvg: pip install pysvg The following sets up a sin wave svg with Python: import pysvg.structure import pysvg.builders import pysvg.text import math svg_document = pysvg.structure.Svg() shape_builder = pysvg.builders.ShapeBuilder() style = pysvg.builders.StyleBuilder() style.setStrokeWidth(2) style.setStroke(&#8216;black&#8217;) def line(a, b): if (a == None): return if (b == None): return (x1, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/generate-a-sin-wave-svg-in-python\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Generate a sin wave svg in Python&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[446,447],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2401"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=2401"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2401\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=2401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=2401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=2401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}