simetri.extensions package¶
Submodules¶
simetri.extensions.l_system module¶
simetri.extensions.ndfsm module¶
simetri.extensions.rekurjon2 module¶
simetri.extensions.svg module¶
simetri.extensions.turtle_sg module¶
Turtle graphics variant, with a twist.
- class simetri.extensions.turtle_sg.State(pos: tuple, angle: float, pen_is_down: bool)[source]¶
Bases:
object
A state of the turtle.
- pos¶
The position of the turtle.
- Type:
tuple
- angle¶
The angle of the turtle.
- Type:
float
- pen_is_down¶
Whether the pen is down.
- Type:
bool
- angle: float¶
- pen_is_down: bool¶
- pos: tuple¶
- class simetri.extensions.turtle_sg.Turtle(*args: Any, in_degrees: bool = False, **kwargs: Any)[source]¶
Bases:
Batch
A Turtle graphics variant, with a twist.
This class implements a turtle graphics system that can be used to draw geometric shapes and patterns.
- Parameters:
*args – Variable length argument list passed to the parent class.
in_degrees (bool, optional) – Whether angles are measured in degrees. Defaults to False.
**kwargs – Arbitrary keyword arguments passed to the parent class.
- property angle: float¶
Return the current angle of the turtle.
The angle is clamped to the appropriate range based on the angle mode.
- Returns:
The current angle, normalized to 0-360 degrees or 0-2π radians.
- Return type:
float
- backward(dist: float | None = None) None [source]¶
Move the turtle backward by the given distance.
- Parameters:
dist (float, optional) – The distance to move backward. Defaults to self.def_dist.
- forward(dist: float | None = None) None [source]¶
Move the turtle forward by the given distance.
Moves the turtle and draws a line if the pen is down.
- Parameters:
dist (float, optional) – The distance to move forward. Defaults to self.def_dist.
- go(dist: float | None = None) None [source]¶
Move the turtle forward without drawing.
Moves the turtle regardless of the pen state, and doesn’t draw. Saves the current path and starts a new one.
- Parameters:
dist (float, optional) – The distance to move forward. Defaults to self.def_dist.
- left(angle: float | None = None) None [source]¶
Turn the turtle left by the given angle.
- Parameters:
angle (float, optional) – The angle to turn left. Defaults to self.def_angle.
- move_to(pos: tuple) None [source]¶
Move the turtle to the given position.
- Parameters:
pos (tuple) – The target position as (x, y) coordinates.
- pen_down() None [source]¶
Lower the pen.
Enables drawing when the turtle moves and adds the current position to the current path.
- pen_up() None [source]¶
Lift the pen.
Stops drawing and saves the current path when the turtle moves.
- pop() None [source]¶
Restore the last saved state of the turtle.
Retrieves the most recently saved state and restores the turtle to it.
- push() None [source]¶
Save the current state of the turtle.
Stores the current position, angle, and pen state for later retrieval.
- reset() None [source]¶
Reset the turtle to its initial state.
Appends the current shape to the batch and resets position, angle, and pen state.
- simetri.extensions.turtle_sg.add_digits(n: int) int [source]¶
Return the sum of the digits of n.
Spirolateral helper function that adds all digits in a number.
- Parameters:
n (int) – The number to process.
- Returns:
The sum of all digits in n.
- Return type:
int
Examples
10 -> 1 + 0 -> 1 123 -> 1 + 2 + 3 -> 6
- simetri.extensions.turtle_sg.spiral(turtle: Turtle, side: float, angle: float, delta: float, cycles: int = 15) Turtle [source]¶
Draw a spiral with the given side, angle, delta, and cycles.
- Parameters:
turtle (Turtle) – The turtle object to use for drawing.
side (float) – Initial length of the side.
angle (float) – Angle to turn after drawing each side.
delta (float) – Amount to increase the side length in each step.
cycles (int, optional) – Number of segments to draw. Defaults to 15.
- Returns:
The turtle object used for drawing.
- Return type:
- simetri.extensions.turtle_sg.spirolateral(sequence: Sequence, angle: float, cycles: int = 15, multiplier: float = 50) Turtle [source]¶
Draw a spirolateral with the given sequence and angle.
- Parameters:
sequence (Sequence) – Sequence of numbers determining segment lengths.
angle (float) – Angle in degrees for turns.
cycles (int, optional) – Number of cycles to draw. Defaults to 15.
multiplier (float, optional) – Scaling factor for segment lengths. Defaults to 50.
- Returns:
The turtle object used for drawing.
- Return type: