summaryrefslogtreecommitdiff
path: root/embroider.py
diff options
context:
space:
mode:
authorLex Neva <github@lexneva.name>2016-10-19 21:43:20 -0400
committerLex Neva <github@lexneva.name>2016-10-19 21:43:23 -0400
commit36085676c8290a957feef4ac3808f0db42ec6881 (patch)
treed5a8be3c641da3266db3745fb61436f020ceac1d /embroider.py
parentb70e0e7fa815c4e79d4470b17bc2339637c401cb (diff)
add center walk and zigzag underlay for satin
the code's a total hack, but it gets the job done
Diffstat (limited to 'embroider.py')
-rw-r--r--embroider.py42
1 files changed, 34 insertions, 8 deletions
diff --git a/embroider.py b/embroider.py
index cad82bc2..7e121f63 100644
--- a/embroider.py
+++ b/embroider.py
@@ -24,6 +24,7 @@ import os
import subprocess
from copy import deepcopy
import time
+from itertools import chain, izip
import inkex
import simplepath
import simplestyle
@@ -1207,6 +1208,9 @@ class Embroider(inkex.Effect):
underlay_inset = get_float_param(node, "satin_underlay_inset", 0)
underlay_stitch_len_px = get_float_param(node, "stitch_length", self.running_stitch_len_px)
underlay = get_boolean_param(node, "satin_underlay", False)
+ center_walk = get_boolean_param(node, "satin_center_walk", False)
+ zigzag_underlay_spacing = get_float_param(node, "satin_zigzag_underlay_spacing", 0)
+ zigzag_underlay_inset = underlay_inset / 2.0
# A path is a collection of tuples, each of the form:
#
@@ -1390,18 +1394,40 @@ class Embroider(inkex.Effect):
add_satin_stitch(end1, end2)
- return zigs, zags
+ return [zigs, zags]
- if underlay:
- forward, back = calculate_satin(underlay_stitch_len_px, -underlay_inset)
+ def calculate_underlay(inset):
+ forward, back = calculate_satin(underlay_stitch_len_px, -inset)
+ return Patch(color=threadcolor, sortorder=sortorder, stitches=(forward + list(reversed(back))))
+
+ def satin_to_patch(zigzag_spacing, pull_compensation, reverse=False):
+ patch = Patch(color=threadcolor, sortorder=sortorder)
+
+ sides = calculate_satin(zigzag_spacing, pull_compensation)
+
+ if reverse:
+ sides.reverse()
+
+ for point in chain.from_iterable(izip(*sides)):
+ patch.addStitch(point)
- patch = Patch(color=threadcolor, sortorder=sortorder, stitches=(forward + list(reversed(back))))
+ if reverse:
+ patch = patch.reverse()
+
+ return patch
+
+ if center_walk:
+ # inset will be clamped to the center point between the stitches
+ patch += calculate_underlay(10000)
+
+ if underlay:
+ patch += calculate_underlay(underlay_inset)
- left_points, right_points = calculate_satin(zigzag_spacing_px, pull_compensation_px)
+ if zigzag_underlay_spacing:
+ patch += satin_to_patch(zigzag_underlay_spacing, -zigzag_underlay_inset)
+ patch += satin_to_patch(zigzag_underlay_spacing, -zigzag_underlay_inset, reverse=True)
- for i in xrange(len(left_points)):
- patch.addStitch(left_points[i])
- patch.addStitch(right_points[i])
+ patch += satin_to_patch(zigzag_spacing_px, pull_compensation_px)
return [patch]