diff options
author | Gary Martin <gary@garycmartin.com> | 2009-04-09 15:09:14 (GMT) |
---|---|---|
committer | Gary Martin <gary@garycmartin.com> | 2009-04-09 15:09:14 (GMT) |
commit | a6e24eac55d93ac6c72ce2c7902d7c65227bbc5e (patch) | |
tree | ee7154d06b482448b43002002fb8f11fdb5453b9 /src | |
parent | 5b1519956ce27537e0580d522c4ab243bb095c53 (diff) |
Added simple drawing smoothing algorithm to reduce line jitter and reduce point count.
Diffstat (limited to 'src')
-rw-r--r-- | src/DrawingThought.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/DrawingThought.py b/src/DrawingThought.py index 29eee41..2c88332 100644 --- a/src/DrawingThought.py +++ b/src/DrawingThought.py @@ -36,6 +36,7 @@ STYLE_CONTINUE=0 STYLE_END=1 STYLE_BEGIN=2 ndraw =0 +SMOOTH = 5 class DrawingThought (ResizableThought): class DrawingPoint (object): @@ -59,6 +60,7 @@ class DrawingThought (ResizableThought): self.text = _("Drawing #%d" % ndraw) self.drawing = 0 self.all_okay = True + self.coords_smooth = [] def draw (self, context): ResizableThought.draw(self, context) @@ -178,6 +180,15 @@ class DrawingThought (ResizableThought): if not self.editing: return False + # Smooth drawing and reduce number of points + self.coords_smooth.append(coords) + if len(self.coords_smooth) < SMOOTH: + return False + else: + coords = (float(sum([i[0] for i in self.coords_smooth])) / SMOOTH, + float(sum([i[1] for i in self.coords_smooth])) / SMOOTH) + self.coords_smooth = [] + if self.drawing == 1: if coords[0] < self.ul[0]+5: self.ul = (coords[0]-5, self.ul[1]) |