Convert turtle commands into G-Code
Project description
Turtle G-Code
A small library for converting python turtle commands into G-Code for use with a pen-plotter.
Simply import this library instead of the default turtle one and then add a call to turtle.write_gcode() at the end to get the G-Code of the shapes you have drawn.
Things this library doesn't support:
- Stamps
- Writing Text
- Different colours/thicknesses of pen
- Undoing actions (undo functions throw an error if called)
Have fun :)
Basic Use
The module is designed to be pretty much a drop in replacement for the normal turtle library.
If (for example) you had this python code
import turtle
turtle.pendown()
turtle.forward(50)
turtle.circle(20)
you could convert it into G-Code by changing it to
import turtle_gcode as turtle
turtle.pendown()
turtle.forward(50)
turtle.circle(20)
turtle.write_gcode(100, 100)
More options
The turtle stores an internal buffer of all the moves made that would write to the output. They can then be output to a string.
There are two functions defined
write_gcode()
Writes the current move buffer as G-Code to the output. The drawing is automatically scaled
to be as large as possible within the specified bounds. If allow_rotation is True then the
drawing may also be rotated if that would allow it to be larger.
All parameters:
width-- the width of the usable area of the plotterheight-- the height of the usable area of the plotterx-- the x coordinate of the bottom left corner of the usable area of the plotter (default 0)y-- the y coordinate of the bottom left corner of the usable area of the plotter (default 0)allow_rotation-- if the drawing should be automatically rotated by 90deg if that will allow it to be drawn bigger in the supplied area (default False)circle_mode-- either 'radius' or 'centre', which circle drawing method the G-Code should use (default 'centre')penup_command-- the G-Code command to send the the plotter to move the pen up, by default no command is sent and the pen is assumed to always be downpendown_command-- the G-Code command to send the the plotter to move the pen down, by default no command is sent and the pen is assumed to always be down
clear_gcode()
Clears all the moves from the G-Code buffer.
License
Like the original turtle code this is under a zlib license.
A small part of the original turtle code is used, again under the original zlib license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file turtle_gcode-0.0.1.tar.gz.
File metadata
- Download URL: turtle_gcode-0.0.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30061386abe7e2a91d9588f0965f84c1742019bed488b34f2379b4682a2a740f
|
|
| MD5 |
b938284bf7fa62f7badbe0228ea1d274
|
|
| BLAKE2b-256 |
7c86e786c47ab1330c29d8a4d156064757ef43a3b69c69506d61cb5c17035f60
|
File details
Details for the file turtle_gcode-0.0.1-py3-none-any.whl.
File metadata
- Download URL: turtle_gcode-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d09b15e2acb1854df448ed94ddf5fc2f557b45b93514ef28873c6347191844df
|
|
| MD5 |
83a99d889a54522122170da9992e174f
|
|
| BLAKE2b-256 |
28370e0139c146acfb496f0a54bd7d818ef9598b71f6a2e48d609df73636df2d
|