Image#
Contains functions for saving turtle drawings.
- superturtle.image.save(filename)[source]#
Saves the canvas as a raster-based image, comparable to taking a screenshot. Suitable file extensions include .png and .jpg.
- Parameters:
filename (str) – Location to save the file, including file extension.
- class superturtle.image.save_svg(width, height, filename, dryrun=False)[source]#
A context manager which saves turtle drawing in SVG format. Drawing within this context manager will be saved to the SVG file, and will not draw on the screen. You can use dryrun=True to draw to the screen instead of to the SVG file while you develop your drawing.
The specified width and height define the SVG’s viewBox, centered on (0, 0). Anything outside of this area will be cut off. If you are planning to draw the resulting SVG with a pen plotter, keep in mind that 1 inch == 96 pixels. A standard sheet of paper (8.5” by 11”) is 816 px by 1056 px.
It can helpful to set the turtle’s canvas to the same size as your drawing so that you can see how your drawing fits on the page. To do this, use turtle’s setup(width, height) function to set the window size and screensize(width, height) function to set the canvas size. It helps to add a couple of extra pixels to the window size to avoid getting scroll bars.
- Parameters:
width (int) – Width of resulting SVG file in pixels.
height (int) – Height of resulting SVG file in pixels.
filename (str) – Location to save resulting SVG.
dryrun (bool) – (Optional) Disable saving to SVG and draw to the screen instead.
from turtle import circle, setup, screensize from superturtle.image import save_svg width, height = 816, 1056 setup(width + 2, height + 2) screensize(width, height) with save_svg(width, height, "image.svg"): circle(100)