summaryrefslogtreecommitdiff
path: root/host/simu/view
diff options
context:
space:
mode:
authorNicolas Schodet2011-04-19 23:50:18 +0200
committerNicolas Schodet2011-04-19 23:50:18 +0200
commita62e936645808b33558168bd2225c96ad388740c (patch)
tree188a59ee81dc2feaeaacfe8df2e49e039c90678e /host/simu/view
parent4a7f10430b7eaa3ac4a133c701d2b50a3db4e401 (diff)
host/simu: add table for Eurobot 2011
Diffstat (limited to 'host/simu/view')
-rw-r--r--host/simu/view/table_eurobot2011.py120
1 files changed, 120 insertions, 0 deletions
diff --git a/host/simu/view/table_eurobot2011.py b/host/simu/view/table_eurobot2011.py
new file mode 100644
index 00000000..64cb66d8
--- /dev/null
+++ b/host/simu/view/table_eurobot2011.py
@@ -0,0 +1,120 @@
+# simu - Robot simulation. {{{
+#
+# Copyright (C) 2009 Nicolas Schodet
+#
+# APBTeam:
+# Web: http://apbteam.org/
+# Email: team AT apbteam DOT org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# }}}
+"""Eurobot 2011 table."""
+from simu.inter.drawable import Drawable
+from simu.utils.trans_matrix import TransMatrix
+from math import pi
+
+RED = '#cc0000'
+BLUE = '#0000cc'
+GREEN = '#006b00'
+BLACK = '#181818'
+YELLOW = '#cccc00'
+
+class Pawn (Drawable):
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ self.model.register (self.__notified)
+ self.__notified ()
+
+ def __notified (self):
+ self.pos = self.model.pos
+ self.update ()
+
+ def draw (self):
+ self.reset ()
+ if self.pos:
+ self.trans_translate (self.pos)
+ r = self.model.radius
+ self.draw_circle ((0, 0), r, fill = YELLOW)
+ if self.model.kind == 'king':
+ a = 0.1 * r
+ b = 0.5 * r
+ self.draw_line ((a, b), (a, a), (b, a), (b, -a), (a, -a),
+ (a, -b), (-a, -b), (-a, -a), (-b, -a), (-b, a),
+ (-a, a), (-a, b), (a, b))
+ elif self.model.kind == 'queen':
+ self.draw_circle ((0, 0), 0.5 * r)
+ self.draw_circle ((0, 0), 0.4 * r)
+ Drawable.draw (self)
+
+class Table (Drawable):
+ """The table and its elements."""
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ for e in model.pawns:
+ Pawn (self, e)
+
+ def draw_both (self, primitive, *args, **kargs):
+ """Draw a primitive on both sides."""
+ primitive (*args, **kargs)
+ primitive (*((3000 - x, y) for x, y in args), **kargs)
+
+ def draw (self):
+ # Redraw.
+ self.reset ()
+ # Table.
+ self.draw_rectangle ((-22, -22), (3000 + 22, 2100 + 22), fill = BLACK)
+ self.draw_rectangle ((0, 0), (3000, 2100), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (0, 0), (400, 2100 - 400 - 22), fill = GREEN)
+ self.draw_rectangle ((0, 2100 - 400), (400, 2100), fill = RED)
+ self.draw_rectangle ((0, 2100 - 400 - 22), (400, 2100 - 400), fill = RED)
+ self.draw_rectangle ((3000, 2100 - 400), (3000 - 400, 2100), fill = BLUE)
+ self.draw_rectangle ((3000, 2100 - 400 - 22), (3000 - 400, 2100 - 400), fill = BLUE)
+ self.draw_rectangle ((1500 - 3 * 350, 0), (1500 + 3 * 350, 2100), fill = BLUE)
+ for i in xrange (-3, 3):
+ for j in xrange (0, 6):
+ if (i + j) % 2:
+ self.draw_rectangle ((1500 + i * 350, j * 350),
+ (1850 + i * 350, 350 + j * 350), fill = RED)
+ # Bonus.
+ for i, j in ((0, 0), (1, 2), (1, 4)):
+ self.draw_circle ((1500 - 175 - i * 350, 175 + j * 350), 50, fill = BLACK)
+ self.draw_circle ((1500 + 175 + i * 350, 175 + j * 350), 50, fill = BLACK)
+ # Protected zones.
+ self.draw_both (self.draw_rectangle, (1500 - 3 * 350, 0), (1500 - 350, 120), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (1500 - 3 * 350, 120), (1500 - 3 * 350 + 22, 120 + 130), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (1500 - 350, 120), (1500 - 350 - 22, 120 + 130), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (1500 - 350, 120 + 130), (1500 - 350 - 20, 350), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (1500 - 3 * 350, 350 - 20), (1500 - 350, 350), fill = BLACK)
+ # Axes.
+ self.draw_line ((0, 200), (0, 0), (200, 0), arrow = 'both')
+ # Beacons.
+ self.draw_both (self.draw_rectangle, (-22, 2100 + 22), (-22 - 80, 2100 + 22 + 80), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (-22, 1050 - 40), (-22 - 80, 1050 + 40), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (-22, -80 - 22), (-22 - 80, -22), fill = BLACK)
+ # Children.
+ Drawable.draw (self)
+
+if __name__ == '__main__':
+ from simu.inter.inter import Inter
+ import simu.model.table_eurobot2011 as model
+ app = Inter ()
+ m = model.Table ()
+ Table (app.table_view, m)
+ app.mainloop ()