A Python package that uses the principles of 3D Turtle Geometry to generate GCODE for 3D-printed solids.
The ExtruderTurtle
class is very simple, and only has a few built-in functions implementing the basic functionality of a turtle.
Here are several methods of the ExtruderTurtle
class that are used to set up your turtle:
- The constructor
t = ExtruderTurtle()
which takes no arguments. The turtle is constructed with a few default values in place:- The default output file name
turtle.gcode
- Default starting orientation, consisting of three vectors:
forward_vec
(which you may imagine as pointing out of the turtle's nose),up_vec
(normal to the turtle's shell), andleft_vec
(pointing out of the turtle's left side). - Default starting
feedrate
(the rate of movement) is0
. - Default starting
density
(ratio of mm extruded to mm moved) is0
. - Default starting
pendown
value (whether or not the turtle extrudes while moving) isTrue
.
- The default output file name
- To change the name of the output file, use
t.name("your-filename.gcode")
. - To write the initialization sequence (which moves the turtle to the initial position, runs the mesh bed leveling, heats the bed and extruder, etc) to the output file, run
t.setup()
, which takes several optional arguments:x=0
is the starting x-valuey=0
is the starting y-valuefeedrate=100
is the starting feedratehotend_temp=215
is the default temp of the hotendbed_temp=60
is the default temp of the bed
- To write the finalization sequence to the output file, use
t.finish()
(which cools down the bed, moves the extruder up, etc).
Here are the basic built-in actions of the turtle:
t.forward(distance)
moves the turtle forward a distance ofdistance
, extruding along the way if the pen is down.t.left(theta)
turns the turtle left by an angletheta
. This is just an easier-to-remember alias fort.yaw(theta)
.t.right(theta)
turns the turtle right by an angletheta
. Alias fort.yaw(-theta)
.t.pitch_up(theta)
tilts the turtle "upwards" in the direction where its eyes would point. Alias fort.pitch(theta)
.t.pitch_down(theta)
tilts the turtle "downwards". Alias fort.pitch(-theta)
.t.roll_left(theta)
rolls the turtle towards its left side. Alias for `t.roll(-theta).t.roll_right(theta)
rolls the turtle towards its right side. Alias fort.roll(theta)
.t.lift(height)
lifts the turtle up by a distanceheight
. Usually used to move to the next layer of the print.t.forward_lift(distance, height)
moves the turtle forward by a distancedistance
and up by a distanceheight
, extruding along the way if the pen is down. Note that "up" here refers to the direction normal to the turtle's shell, not necessarily in the positive-z direction.t.penup()
lifts the pen up (extrusion will not occur until the pen is back down).t.pendown()
puts the pen down (extrusion will occur until the pen is lifted up again).t.do(command)
will write a manually-written custom GCODE commandcommand
to the output file.
The following functions are used to configure the turtle and the style of the print:
t.set_density(density)
sets the density of extrusion, that is, the ratio of mm filament extruded to mm moved by the turtle.t.rate(feedrate)
sets the feedrate (think speed) of the turtle.t.track_history
is a boolean value, defaultFalse
, which, when true, stores a list of all points previously visited by the turtle, and all line segments on which extrusion occurred. This is used primarily for visualization.
You may use Rhino/Grasshopper to visualize a preview of your 3D print before sending it to your printer, if you wish.
The extruder_turtle library does not make use of any libraries that require distributions later than Python 2.7, so it can be used with RhinoPython. However, it needs to be installed separately, in a special directory containing Python packages used by Rhino/Grasshopper. On Mac OS, RhinoPython libraries are installed in the directory
/Users/YOUR_USERNAME/Applications/Rhino\ 7.app/Contents/Frameworks/RhCore.framework/Versions/Current/Resources/ManagedPlugIns/RhinoDLR_Python.rhp/Lib
You can simply save a copy of ExtruderTurtle.py
to the Lib
folder, and you should be able to use it from within Grasshopper. You may also need to add a folder called data
containing initseq.gcode
and finalseq.gcode
, since these files are necessary for using the turtle to generate GCODE. Note that you may need to run Rhino as admin in order for it to have permission to open these files while running.
An example visualization with Grasshopper is given in turtletest.gh
in the demos
folder (it shows how to visualize an example identical to the one generated in demos/seven_star.py
).
In the demos
folder, you can find a few snippets of example code using ExtruderTurtle
to generate GCODE files for interesting 3D prints. Here are descriptions of these demos, in roughly increasing order of complexity:
seven_star.py
: draws a self-intersecting star polygon with seven points.spiral.py
: draws a flat circle of plastic by tracing out a very tight spiral.nonplanar_star.py
: draws the same star polygon asseven_star.py
, but slightly concave down, so that the middle is higher than the points, using nonplanar slicing to make a smooth curve rather than one with stair-steppingdreamcatcher.py
: creates a dreamcatcher-like design by tracing out a very thin cylinder filled with random chords.snowflake_lsystem.py
: encodes the Koch Snowflake as an L-System with substitution rules, which it uses to generate a sequence of instructions for the turtle to follow to trace out the Snowflakecomplex_walk.py
: uses the mathematical properties and symmetries of a certain class of walks in the complex plane to generate a beautiful shape.evolving_snowflake.py
: draws the successive generations by which a Koch Snowflake fractal is produced, in such a way that they appear to "morph into" each other.