Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 82d3446

Browse filesBrowse files
committed
Add Satin stitch
1 parent 87ede52 commit 82d3446
Copy full SHA for 82d3446

File tree

2 files changed

+71
-0
lines changed
Filter options

2 files changed

+71
-0
lines changed

‎src/turtlethread/stitches.py

Copy file name to clipboardExpand all lines: src/turtlethread/stitches.py
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,47 @@ def _get_stitch_commands(self) -> list[tuple[float, float, StitchCommand]]:
271271
stitch_commands.extend(self._iter_zigzag_between_positions(pos1, pos2))
272272
return stitch_commands
273273

274+
class SatinStitch(StitchGroup):
275+
"""Stitch group for satin stitches.
276+
Satin stitches create a dense, closely packed fill of stitches between two locations, similar to a zigzag stitch,
277+
but with more closely spaced and finer stitch density.
278+
Parameters
279+
----------
280+
stitch_length : float
281+
Distance between each satin stitch point.
282+
amplitude : float
283+
The distance from the central path to each side of the satin stitch.
284+
density : float (optional, default=5.0)
285+
Affects how closely packed the stitches are. Higher density means more stitches per unit of distance.
286+
"""
287+
def __init__(self, start_pos: Vec2D, stitch_length: float, amplitude: float, density: float = 5.0) -> None:
288+
super().__init__(start_pos=start_pos)
289+
self.stitch_length = stitch_length
290+
self.amplitude = amplitude
291+
self.density = density # Default density is higher for satin stitches (more closely packed)
292+
def _iter_satin_between_positions(self, position_1: Vec2D, position_2: Vec2D) -> Generator[tuple[float, float, StitchCommand], None, None]:
293+
x1, y1 = position_1
294+
x2, y2 = position_2
295+
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
296+
angle = math.atan2(y2 - y1, x2 - x1)
297+
dx = math.cos(angle)
298+
dy = math.sin(angle)
299+
# Adjust stitch length based on density
300+
effective_stitch_length = self.stitch_length / self.density
301+
distance_traveled = 0
302+
satin_side = -1 # Start on one side of the line
303+
while distance_traveled + effective_stitch_length <= distance:
304+
x1 += effective_stitch_length * dx
305+
y1 += effective_stitch_length * dy
306+
distance_traveled += effective_stitch_length
307+
# Calculate offset for satin pattern (smaller amplitude than zigzag)
308+
offset_x = satin_side * self.amplitude * -dy # Perpendicular to the line
309+
offset_y = satin_side * self.amplitude * dx
310+
yield x1 + offset_x, y1 + offset_y, pyembroidery.STITCH
311+
satin_side *= -1 # Switch side
312+
# Add the final point exactly at the end of the line
313+
yield x2, y2, pyembroidery.STITCH
314+
274315
class JumpStitch(StitchGroup):
275316
"""Stitch group for jump stitches.
276317

‎src/turtlethread/turtle.py

Copy file name to clipboardExpand all lines: src/turtlethread/turtle.py
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,21 @@ def start_zigzag_stitch(self, stitch_length, amplitude, density=1.0):
221221
"""
222222
self.set_stitch_type(stitches.ZigzagStitch(self.pos(), stitch_length, amplitude, density))
223223

224+
def start_satin_stitch(self, stitch_length, amplitude, density=5.0):
225+
"""Set the stitch mode to satin stitch (not recommended, use ``satin_stitch``-context instead).
226+
Satin stitches create a dense, closely packed fill of stitches between two locations, similar to a zigzag stitch,
227+
but with more closely spaced and finer stitch density.
228+
Parameters
229+
----------
230+
stitch_length : float
231+
Distance between each satin stitch point.
232+
amplitude : float
233+
The distance from the central path to each side of the satin stitch.
234+
density : float (optional, default=5.0)
235+
Affects how closely packed the stitches are. Higher density means more stitches per unit of distance.
236+
"""
237+
self.set_stitch_type(stitches.SatinStitch(self.pos(), stitch_length, amplitude, density))
238+
224239
def start_jump_stitch(self):
225240
"""Set the stitch mode to jump-stitch (not recommended, use ``jump_stitch``-context instead).
226241
@@ -302,6 +317,21 @@ def zigzag_stitch(self, stitch_length, amplitude, density=1.0):
302317
"""
303318
return self.use_stitch_group(stitches.ZigzagStitch(self.pos(), stitch_length, amplitude, density))
304319

320+
def satin_stitch(self, stitch_length, amplitude, density=5.0):
321+
"""Set the stitch mode to satin stitch and cleanup afterwards.
322+
Satin stitches create a dense, closely packed fill of stitches between two locations, similar to a zigzag stitch,
323+
but with more closely spaced and finer stitch density.
324+
Parameters
325+
----------
326+
stitch_length : float
327+
Distance between each satin stitch point.
328+
amplitude : float
329+
The distance from the central path to each side of the satin stitch.
330+
density : float (optional, default=5.0)
331+
Affects how closely packed the stitches are. Higher density means more stitches per unit of distance.
332+
"""
333+
return self.use_stitch_group(stitches.SatinStitch(self.pos(), stitch_length, amplitude, density))
334+
305335
def jump_stitch(self, skip_intermediate_jumps=True):
306336
"""Set the stitch mode to jump-stitch and cleanup afterwards.
307337

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.