diff options
Diffstat (limited to 'lib/stitches/ripple_stitch.py')
| -rw-r--r-- | lib/stitches/ripple_stitch.py | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/lib/stitches/ripple_stitch.py b/lib/stitches/ripple_stitch.py index 156059e9..02dbdeb2 100644 --- a/lib/stitches/ripple_stitch.py +++ b/lib/stitches/ripple_stitch.py @@ -7,10 +7,11 @@ from shapely.geometry import LineString, Point from ..elements import SatinColumn from ..utils import Point as InkstitchPoint +from ..utils import prng from ..utils.geometry import line_string_to_point_list from ..utils.threading import check_stop_flag from .guided_fill import apply_stitches -from .running_stitch import running_stitch +from .running_stitch import even_running_stitch, running_stitch def ripple_stitch(stroke): @@ -46,33 +47,50 @@ def _get_stitches(stroke, is_linear, lines, skip_start): return _get_staggered_stitches(stroke, lines, skip_start) else: points = [point for line in lines for point in line] - return running_stitch(points, stroke.running_stitch_length, stroke.running_stitch_tolerance) + return running_stitch(points, + stroke.running_stitch_length, + stroke.running_stitch_tolerance, + stroke.enable_random_stitches, + stroke.random_stitch_length_jitter, + stroke.random_seed) def _get_staggered_stitches(stroke, lines, skip_start): stitches = [] + stitch_length = stroke.running_stitch_length + tolerance = stroke.running_stitch_tolerance + enable_random = stroke.enable_random_stitches + length_sigma = stroke.random_stitch_length_jitter + random_seed = stroke.random_seed + last_point = None for i, line in enumerate(lines): - stitched_line = [] connector = [] if i != 0 and stroke.join_style == 0: if i % 2 == 0: - last_point = lines[i-1][0] first_point = line[0] else: - last_point = lines[i-1][-1] first_point = line[-1] - connector = running_stitch([InkstitchPoint(*last_point), InkstitchPoint(*first_point)], - stroke.running_stitch_length, - stroke.running_stitch_tolerance) - points = list(apply_stitches(LineString(line), stroke.running_stitch_length, stroke.staggers, 0.5, i, stroke.running_stitch_tolerance).coords) - stitched_line.extend([InkstitchPoint(*point) for point in points]) - if i % 2 == 1 and stroke.join_style == 0: - # reverse every other row in linear ripple - stitched_line.reverse() - if (stroke.join_style == 1 and ((i % 2 == 1 and skip_start % 2 == 0) or - (i % 2 == 0 and skip_start % 2 == 1))): - stitched_line.reverse() - stitched_line = connector + stitched_line + connector = even_running_stitch([last_point, first_point], + stitch_length, tolerance)[1:-1] + if stroke.join_style == 0: + should_reverse = i % 2 == 1 + elif stroke.join_style == 1: + should_reverse = (i + skip_start) % 2 == 1 + + if enable_random or stroke.staggers == 0: + if should_reverse: + line.reverse() + points = running_stitch(line, stitch_length, tolerance, enable_random, length_sigma, prng.join_args(random_seed, i)) + stitched_line = connector + points + else: + # uses the guided fill alforithm to stagger rows of stitches + points = list(apply_stitches(LineString(line), stitch_length, stroke.staggers, 0.5, i, tolerance).coords) + stitched_line = [InkstitchPoint(*point) for point in points] + if should_reverse: + stitched_line.reverse() + stitched_line = connector + stitched_line + + last_point = stitched_line[-1] stitches.extend(stitched_line) return stitches @@ -137,9 +155,9 @@ def _get_helper_lines(stroke): if len(lines) > 1: return True, _get_satin_ripple_helper_lines(stroke) else: - outline = LineString(running_stitch(line_string_to_point_list(lines[0]), - stroke.grid_size or stroke.running_stitch_length, - stroke.running_stitch_tolerance)) + outline = LineString(even_running_stitch(line_string_to_point_list(lines[0]), + stroke.grid_size or stroke.running_stitch_length, + stroke.running_stitch_tolerance)) if stroke.is_closed: return False, _get_circular_ripple_helper_lines(stroke, outline) @@ -278,7 +296,7 @@ def _get_guided_helper_lines(stroke, outline, max_distance): def _generate_guided_helper_lines(stroke, outline, max_distance, guide_line): # helper lines are generated by making copies of the outline along the guide line line_point_dict = defaultdict(list) - outline = LineString(running_stitch(line_string_to_point_list(outline), max_distance, stroke.running_stitch_tolerance)) + outline = LineString(even_running_stitch(line_string_to_point_list(outline), max_distance, stroke.running_stitch_tolerance)) center = outline.centroid center = InkstitchPoint(center.x, center.y) |
