Saving output of Turtle Graphics?

Dick Moores rdm at rcblue.com
Sat Apr 7 12:14:51 EDT 2007


At 08:48 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu=B3a?= wrote:
>Dick Moores wrote:
> >> Turtle module uses Tk canvas element to draw graphics ('_canvas'
> >> attribute). I've written module, that exports canvas graphics to SVG
> >> file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
> >> for you.
> >
> > I afraid I'm totally unfamiliar with SVG. Would it be possible for you
> > or someone else on the list to show how to use your module to export the
> > simple product of this simple script to an SVG file?
> >
> > ===============================================
> > import turtle as T
>import canvasvg
> > from random import randint
> > T.setup(width=1000, height=700, startx=0, starty=0)
> > T.color(1, .5, .5)
> > T.begin_fill()
> > # 2 connected lines will fill as a triangle
> > for x in range(2):
> >     coord = (randint(-500,500), randint(-350,350))
> >     T.goto(coord)
> > T.end_fill()
>
>canvasvg.saveall("image.svg", T._canvas)
>
> > T.done()
> > ================================================

OK, thanks, now I've got

===========================================================
<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 
1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg 
height="246.000" viewBox="8.000 338.000 504.000 246.000" 
width="504.000" xmlns="http://www.w3.org/2000/svg"><line fill="none" 
stroke="#ff8080" stroke-linecap="round" x1="500.0" x2="20.0" 
y1="350.0" y2="426.0"/><line fill="none" stroke="#ff8080" 
stroke-linecap="round" x1="20.0" x2="368.0" y1="426.0" 
y2="569.0"/><line fill="none" stroke="#ff8080" stroke-linecap="round" 
x1="360.0" x2="368.0" y1="569.0" y2="569.0"/><polygon fill="#ff8080" 
points="368.0 569.0 358.0 572.0 360.0 569.0 358.0 566.0"/><polygon 
fill="#ff8080" fill-rule="evenodd" points="500.0,350.0 20.0,426.0 
368.0,569.0" stroke-linejoin="round"/></svg>
============================================================

What do I do to see this?

Dick




More information about the Python-list mailing list