Generating SVG from turtle graphics

Peter Otten __peter__ at web.de
Sun Jan 14 05:31:34 EST 2018


Steven D'Aprano wrote:

> I'd like to draw something with turtle, then generate a SVG file from it.
> 
> Is this possible?

If this is a one-off job consider creating Postscript from the underlying 
Canvas:

>>> import turtle
>>> for i in range(12):
...     turtle.forward(100)
...     turtle.left(150)
... 
>>> turtle.getcanvas().postscript(file="tmp_turtle.ps")
[...]

Then convert to SVG with an external tool. It looks like ghostscript can do
that:

$ gs -dBATCH -dNOPAUSE -sDEVICE=svg -sOutputFile=tmp_turtle.svg tmp_turtle.ps





More information about the Python-list mailing list