Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGary Martin <gary@garycmartin.com>2009-04-09 15:09:14 (GMT)
committer Gary Martin <gary@garycmartin.com>2009-04-09 15:09:14 (GMT)
commita6e24eac55d93ac6c72ce2c7902d7c65227bbc5e (patch)
treeee7154d06b482448b43002002fb8f11fdb5453b9 /src
parent5b1519956ce27537e0580d522c4ab243bb095c53 (diff)
Added simple drawing smoothing algorithm to reduce line jitter and reduce point count.
Diffstat (limited to 'src')
-rw-r--r--src/DrawingThought.py11
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])