CCCPaste

turtle2svg.py

#!/usr/bin/python3
import turtle
import time
import os
"""
I couldnt make svg_turtle work, so I did some hacky bs instead
anyway, we hide the turtle cursor, get the canvas, save the file 
then show the currsor again. this prevents the curror from 
appearing in the saved image

This program saves the turtle canvas as an svg. 
and a post script file, (whatever rm it)
as the current unix time. 

ep2svg is provided by the geg package

"""

# Draw something with the turtle
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)

# Get the current Unix time
current_time = int(time.time())

print("Current Unix time:", current_time)
#hide the turtle for file write
turtle.hideturtle()
# Get the turtle canvas as a string
canvas_data = turtle.getcanvas().postscript()

# Construct the file name with the current time and the .ps extension
ps_file_name = f"{current_time}.ps"
svg_file_name = f"{current_time}.svg"

# Write the canvas data to a PostScript file
with open(ps_file_name, 'w') as f:
    f.write(canvas_data)

# Show the turtle again
turtle.showturtle()


# Convert the PostScript file to SVG
os.system('eps2svg ' + ps_file_name + ' ' + svg_file_name)
# Close the turtle graphics window
turtle.done()