summaryrefslogtreecommitdiffhomepage log msg author committer range
diff options
 context: 12345678910152025303540 space: includeignore mode: unifiedssdiffstat only
author committer Nicolas Schodet 2012-03-30 20:50:49 +0200 Nicolas Schodet 2012-03-30 20:50:49 +0200 5547ac115e1a4e7c5b294e10c29550e8024990ae (patch) 9250d5972d8eba287ccedaef0ddce7236611775d 3c491b8c4ac9b6a502e510ba9d61cbeda2b4d128 (diff)
host/simu/inter: add draw_oval using a smooth polygon
-rw-r--r--host/simu/inter/drawable.py23
-rw-r--r--host/simu/inter/test/test_drawable.py1
2 files changed, 23 insertions, 1 deletions
 diff --git a/host/simu/inter/drawable.py b/host/simu/inter/drawable.pyindex af7c62a2..849eddd3 100644--- a/host/simu/inter/drawable.py+++ b/host/simu/inter/drawable.py@@ -22,7 +22,7 @@ # # }}} """Drawable and DrawableCanvas."""-from math import sqrt, degrees+from math import sqrt, degrees, pi, cos, sin import simu.utils.trans_matrix import Tkinter @@ -69,6 +69,22 @@ class Drawable: r = self.trans_apply_distance (r) return self.__onto.__draw_circle (p, r, **kw) + def __draw_oval (self, p, rx, ry, **kw):+ v = [ ]+ n = 8+ sx = rx / cos (pi / n)+ sy = ry / cos (pi / n)+ for i in xrange (0, n):+ a = i * 2 * pi / n+ v.append ((p[0] + cos (a) * sx, p[1] + sin (a) * sy))+ kw = kw.copy ()+ if 'fill' not in kw:+ kw['fill'] = ''+ if 'outline' not in kw:+ kw['outline'] = 'black'+ kw['smooth'] = True+ return self.__draw_polygon (*v, **kw)+ def __draw_arc (self, p, r, **kw): p = self.trans_apply (p) r = self.trans_apply_distance (r)@@ -94,6 +110,11 @@ class Drawable: """Draw a circle of the given radius centered on p.""" self.__items.append (self.__draw_circle (p, r, **kw)) + def draw_oval (self, p, rx, ry, **kw):+ """Draw an oval of the given radii (rx along x, ry along y), centered+ on p."""+ self.__items.append (self.__draw_oval (p, rx, ry, **kw))+ def draw_arc (self, p, r, **kw): """Draw a arc of the given radius centered on p.""" self.__items.append (self.__draw_arc (p, r, **kw))diff --git a/host/simu/inter/test/test_drawable.py b/host/simu/inter/test/test_drawable.pyindex a9c1bfef..9aa56ef1 100644--- a/host/simu/inter/test/test_drawable.py+++ b/host/simu/inter/test/test_drawable.py@@ -34,6 +34,7 @@ class Test (Drawable): self.draw_line ((20, 20), (25, 25), (80, 0), (0, 80), fill = 'green') self.draw_line ((20, 20), (25, 25), (80, 0), (0, 80), smooth = True) self.draw_circle ((40, -40), 10)+ self.draw_oval ((40, -40), 10, 5) self.draw_arc ((-40, 0), 20, start = pi / 4, extent = pi / 2) class App (DrawableCanvas):