Turtle (3-D)¶
Pure-Python port of BOSL2’s turtle3d.scad as a Turtle3D class. A turtle
walks through 3-D space carrying an orientation frame; a flat list of commands drives it, and the
result is either the list of points it visited (points()) or a list of
4x4 transforms (transforms()) ready to sweep a profile with
path_sweep() / sweep().
The full simple command set is ported — moves (move/jump/xmove …), relative turns
(left/right/up/down/roll), absolute turns (xrot/yrot/zrot/rot/
setdir), arcs (arcleft/arcright/arcup/arcdown/arcxrot …/arctodir/
arcrot), the length/angle/scale/arcsteps settings, and repeat. Compound
commands are also supported — a single nested list starting with "move" or "arc" that applies
several effects at once (["move", 40, "grow", 2, "twist", 180, "steps", 40]), with
grow/shrink scaling the swept profile, twist rotating it, roll/rollto rolling the
frame, and, for arc, relative or absolute rotation.
-
class pybosl2.turtle.turtle3d.Turtle3D(state=
Anchor.RIGHT)[source]¶ Bases:
objectA 3-D turtle: walk it with a command list to produce a path or a list of sweep transforms.
The turtle starts at the origin pointing in state (default
RIGHT= +X), with “up” along +Z. Commands are a flat list ofTurtleCommandobjects. Turns:left/right(about up),up/down(about side),roll(about heading), and absolutexrot/yrot/zrot. Arcs:arcleft/arcright/arcup/arcdown/arcxrot/arcyrot/arczrot.move/jumptranslate;length/angle/scale/arcstepsset defaults;repeatrepeats. A compoundTurtleCommand(is_compound=True) applies several effects at once (grow/shrink/twist/roll/steps/reverse).Examples
A rounded square path swept into a tube:
from pybosl2.turtle import turtle3d, TurtleCommand, TurtleCommandType as Tct from pybosl2.path3d import Path3D sq = [[-1, -1], [1, -1], [1, 1], [-1, 1]] path = turtle3d([ TurtleCommand(Tct.MOVE, size=20), TurtleCommand(Tct.ARCLEFT, radius=3), TurtleCommand(Tct.MOVE, size=20), TurtleCommand(Tct.ARCLEFT, radius=3), TurtleCommand(Tct.MOVE, size=20), TurtleCommand(Tct.ARCLEFT, radius=3), TurtleCommand(Tct.MOVE, size=20), TurtleCommand(Tct.ARCLEFT, radius=3), ]).points() Path3D(path).path_sweep(sq, closed=True).polyhedron().show()Loading 3-D preview…-
run(commands, repeat=
1)[source]¶ Execute commands (optionally repeat times), advancing this turtle’s state.
- points()[source]¶
Return the de-duplicated list of 3-D points the turtle has visited.
- Return type:¶
list[list[float]]
-
stroke(width=
1, cap=None, closed=None)[source]¶ Render the turtle’s current path as a 3-D stroked tube.
-
run(commands, repeat=