From 72b001e7c227131a01d3bf3ae8678b704127de77 Mon Sep 17 00:00:00 2001 From: Claudine Date: Sun, 6 Nov 2022 11:03:47 -0500 Subject: [PATCH] add random parameters to satin columns --- icons/randomize_20x20.png | Bin 0 -> 697 bytes lib/elements/satin_column.py | 103 ++++++++++++++++++++++++++++++++--- lib/extensions/params.py | 25 +++++++++ lib/svg/tags.py | 7 +++ 4 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 icons/randomize_20x20.png diff --git a/icons/randomize_20x20.png b/icons/randomize_20x20.png new file mode 100644 index 0000000000000000000000000000000000000000..40d8e88ba39bde659767d0272d93aaee2496c44f GIT binary patch literal 697 zcmV;q0!ICbP)pF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H10!B$h zK~y-6h15@oS5*`T@Xzvewh)C12NQx-hw$_bkkn0qq zh@xx}WMM@RnAjp{5sn3sAVd;cizpp4<+ONr?Dgh1`ryEO_kPd!e$Tn@d{vd@0+X1- zr!D3%dA*#p#Q!}>Zo~6<4*%e-w)IRq`Uv<46fiYe1q3T*@RS5;eZ4{paa)>YM(s(OD6nW4g6t(QOa5mhyxFXIFDxuah(GWr_74ds zhRCWqkz^%SCwW#kibKq~B&!DfyQc6WwkNr@mvB{Q1aIJ#aT5DvNv3rpd10ix-ShY< z$^NzpU+XU8{$t=L8*T)&%D6aRPT`gj7!CqX@xzdJfZqqAa zzN+SQlQNATb#8N3_iNqMQ*;J*;eo1pw5q=C_hLD>zE?M&7h5beMMwIImgHT}&KvPY f9B#4kM)-dLqaJ5w*`o1!00000NkvXXu0mjfE+I 0: add_pair(pos0, pos1) @@ -842,8 +915,7 @@ class SatinColumn(EmbroideryElement): patch = StitchGroup(color=self.color) - sides = self.plot_points_on_rails(self.zigzag_underlay_spacing / 2.0, - -self.zigzag_underlay_inset) + sides = self.plot_points_on_rails(self.zigzag_underlay_spacing / 2.0, -self.zigzag_underlay_inset) if self._center_walk_is_odd(): sides = [list(reversed(sides[0])), list(reversed(sides[1]))] @@ -953,7 +1025,12 @@ class SatinColumn(EmbroideryElement): split_count = count or int(-(-distance // max_stitch_length)) for i in range(split_count): line = shgeo.LineString((left, right)) - split_point = line.interpolate((i+1)/split_count, normalized=True) + + random_move = 0 + if self.random_split_factor and i != split_count-1: + random_move = random.uniform(-self.random_split_factor / 100, self.random_split_factor / 100) + + split_point = line.interpolate((i + 1 + random_move) / split_count, normalized=True) points.append(Point(split_point.x, split_point.y)) return [points, split_count] @@ -978,6 +1055,16 @@ class SatinColumn(EmbroideryElement): # beziers. The boundary points between beziers serve as "checkpoints", # allowing the user to control how the zigzags flow around corners. + # If no seed is defined, compute one randomly using time to seed, otherwise, use stored seed + + if self.use_seed == 0: + random.seed() + x = random.randint(1, 10000) + random.seed(x) + self.set_param("use_seed", x) + else: + random.seed(self.use_seed) + patch = StitchGroup(color=self.color) if self.center_walk_underlay: diff --git a/lib/extensions/params.py b/lib/extensions/params.py index df62128f1..7d38b5ffe 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -6,6 +6,7 @@ # -*- coding: UTF-8 -*- import os +import random import sys from collections import defaultdict from copy import copy @@ -78,6 +79,9 @@ class ParamsTab(ScrolledPanel): self.pencil_icon = wx.Image(os.path.join(get_resource_dir( "icons"), "pencil_20x20.png")).ConvertToBitmap() + self.randomize_icon = wx.Image(os.path.join(get_resource_dir( + "icons"), "randomize_20x20.png")).ConvertToBitmap() + self.__set_properties() self.__do_layout() @@ -187,6 +191,16 @@ class ParamsTab(ScrolledPanel): return values + def on_change_seed(self, event): + + for node in self.nodes: + random.seed() + new_seed = random.randint(1, 10000) + node.set_param("use_seed", new_seed) + if self.on_change_hook: + self.on_change_hook(self) + event.Skip() + def apply(self): values = self.get_values() for node in self.nodes: @@ -379,6 +393,17 @@ class ParamsTab(ScrolledPanel): self.inputs_to_params = {v: k for k, v in self.param_inputs.items()} box.Add(self.settings_grid, proportion=1, flag=wx.ALL, border=10) + + add_seed_button = False + for param in self.params: + if param.name[:6] == "random": + add_seed_button = True + if add_seed_button: + self.change_seed_button = wx.Button(self, wx.ID_ANY, _("Change Seed")) + self.change_seed_button.Bind(wx.EVT_BUTTON, self.on_change_seed) + self.change_seed_button.SetBitmap(self.randomize_icon) + box.Add(self.change_seed_button, proportion=0, flag=wx.ALIGN_CENTER_HORIZONTAL, border=10) + self.SetSizer(box) self.update_choice_widgets() diff --git a/lib/svg/tags.py b/lib/svg/tags.py index 06c402dc8..a4dfa0bae 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -119,6 +119,13 @@ inkstitch_attribs = [ 'pull_compensation_percent', 'pull_compensation_rails', 'stroke_first', + 'random_split_factor', + 'random_first_rail_factor_in', + 'random_first_rail_factor_out', + 'random_second_rail_factor_in', + 'random_second_rail_factor_out', + 'random_zigzag_spacing', + 'use_seed', # stitch_plan 'invisible_layers', # Legacy