diff options
| author | Lex Neva <github@lexneva.name> | 2016-10-19 21:43:20 -0400 |
|---|---|---|
| committer | Lex Neva <github@lexneva.name> | 2016-10-19 21:43:23 -0400 |
| commit | 36085676c8290a957feef4ac3808f0db42ec6881 (patch) | |
| tree | d5a8be3c641da3266db3745fb61436f020ceac1d | |
| parent | b70e0e7fa815c4e79d4470b17bc2339637c401cb (diff) | |
add center walk and zigzag underlay for satin
the code's a total hack, but it gets the job done
| -rw-r--r-- | embroider.py | 42 | ||||
| -rw-r--r-- | embroider_params.inx | 2 | ||||
| -rw-r--r-- | embroider_params.py | 2 |
3 files changed, 38 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] diff --git a/embroider_params.inx b/embroider_params.inx index e808e822..1e19bdb4 100644 --- a/embroider_params.inx +++ b/embroider_params.inx @@ -16,6 +16,8 @@ <param name="satin_column" type="string" _gui-text="Satin Column? (yes/no)"></param> <param name="satin_underlay" type="string" _gui-text="Edge-walk underlay for satin Column? (yes/no)"></param> <param name="satin_underlay_inset" type="string" _gui-text="Inset for satin colum underlay (pixels)"></param> + <param name="satin_center_walk" type="string" _gui-text="Satin center walk underlay? (yes/no)"></param> + <param name="satin_zigzag_underlay_spacing" type="string" _gui-text="Zigzag underlay spacing (pixels)"></param> <param name="stroke_first" type="string" _gui-text="Stitch stroke before fill? (yes/no)"></param> <effect> <object-type>all</object-type> diff --git a/embroider_params.py b/embroider_params.py index 03390c3b..20f6c222 100644 --- a/embroider_params.py +++ b/embroider_params.py @@ -28,6 +28,8 @@ class EmbroiderParams(inkex.Effect): "pull_compensation", "satin_underlay", "satin_underlay_inset", + "satin_center_walk", + "satin_zigzag_underlay_spacing", ] for param in self.params: |
