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.
Metadata
Release files for turtle-gcode 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| turtle_gcode-0.0.1.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| turtle_gcode-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.0 kB
Release files / turtle_gcode-0.0.1.tar.gz
| Download URL | turtle_gcode-0.0.1.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30061386abe7e2a91d9588f0965f84c1742019bed488b34f2379b4682a2a740f
|
|
BLAKE2b-256 checksum How to use checksums |
7c86e786c47ab1330c29d8a4d156064757ef43a3b69c69506d61cb5c17035f60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / turtle_gcode-0.0.1-py3-none-any.whl
| Download URL | turtle_gcode-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d09b15e2acb1854df448ed94ddf5fc2f557b45b93514ef28873c6347191844df
|
|
BLAKE2b-256 checksum How to use checksums |
28370e0139c146acfb496f0a54bd7d818ef9598b71f6a2e48d609df73636df2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|