From c2388a53a66be19199f84d332cfb9f613512db4a Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 31 Dec 2017 22:24:18 -0500 Subject: [PATCH] adjust default simulation speed to always take ~5 seconds --- embroider_params.py | 2 +- embroider_simulate.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/embroider_params.py b/embroider_params.py index 1be108810..8300cbc24 100644 --- a/embroider_params.py +++ b/embroider_params.py @@ -401,7 +401,7 @@ class SettingsFrame(wx.Frame): simulator_pos.x += 5 try: - self.simulate_window = EmbroiderySimulator(None, -1, "Embroidery Simulator", simulator_pos, size=(300, 300), patches=patches, on_close=self.simulate_window_closed, stitches_per_frame=10) + self.simulate_window = EmbroiderySimulator(None, -1, "Embroidery Simulator", simulator_pos, size=(300, 300), patches=patches, on_close=self.simulate_window_closed, target_duration=5) except: with open('/tmp/params_debug.log', 'a') as log: print >> log, traceback.format_exc() diff --git a/embroider_simulate.py b/embroider_simulate.py index 2d913bbb7..6fdff57c4 100644 --- a/embroider_simulate.py +++ b/embroider_simulate.py @@ -14,6 +14,7 @@ class EmbroiderySimulator(wx.Frame): self.on_close_hook = kwargs.pop('on_close', None) self.frame_period = kwargs.pop('frame_period', 80) self.stitches_per_frame = kwargs.pop('stitches_per_frame', 1) + self.target_duration = kwargs.pop('target_duration', None) wx.Frame.__init__(self, *args, **kwargs) @@ -22,6 +23,9 @@ class EmbroiderySimulator(wx.Frame): self.load(stitch_file, patches) + if self.target_duration: + self.adjust_speed(self.target_duration) + self.buffer = wx.Bitmap(self.width, self.height) self.dc = wx.MemoryDC() self.dc.SelectObject(self.buffer) @@ -51,6 +55,14 @@ class EmbroiderySimulator(wx.Frame): self.width, self.height = self.get_dimensions() + def adjust_speed(self, duration): + self.frame_period = 1000 * float(duration) / len(self.segments) + self.stitches_per_frame = 1 + + while self.frame_period < 1.0: + self.frame_period *= 2 + self.stitches_per_frame *= 2 + def on_key_down(self, event): keycode = event.GetKeyCode()