summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2012-09-30 23:41:17 +0200
committerNicolas Schodet2012-09-30 23:41:17 +0200
commit9331039ea9f9296e321562bb4d8a7e6d52d6d6d8 (patch)
tree450564670d833e0e0507672d4a452558915d09a2
parente0af2996b1fcf8467253813a9406532e0b8a50cb (diff)
host/simu: add Eurobot 2013 table
-rw-r--r--host/simu/model/table_eurobot2013.py115
-rw-r--r--host/simu/view/table_eurobot2013.py208
2 files changed, 323 insertions, 0 deletions
diff --git a/host/simu/model/table_eurobot2013.py b/host/simu/model/table_eurobot2013.py
new file mode 100644
index 00000000..5fb663f4
--- /dev/null
+++ b/host/simu/model/table_eurobot2013.py
@@ -0,0 +1,115 @@
+# simu - Robot simulation. {{{
+#
+# Copyright (C) 2012 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.
+#
+# }}}
+"""Table model for Eurobot 2013."""
+import simu.model.table
+from simu.model.round_obstacle import RoundObstacle
+from simu.model.rectangular_obstacle import RectangularObstacle
+from math import pi
+import math
+import random
+
+class Table (simu.model.table.Table):
+
+ def __init__ (self, cards = None):
+ simu.model.table.Table.__init__ (self)
+ # Candles.
+ self.candles = [ ]
+ def add_candle (pos, level, color):
+ candle = RoundObstacle (40, level)
+ candle.pos = pos
+ candle.color = color
+ candle.state = False
+ self.candles.append (candle)
+ def add_candle_circle (center, radius, start, step, colors, level):
+ angle = start
+ for color in colors:
+ pos = (center[0] + radius * math.cos (angle),
+ center[1] + radius * math.sin (angle))
+ add_candle (pos, level, color)
+ angle += step
+ colors_r = [ False, False, False, True, True, True ]
+ random.shuffle (colors_r)
+ colors = [ False ] + colors_r + [ True ]
+ add_candle_circle ((1500, 2000), 350, pi + pi / 16, pi / 8, colors, 3)
+ colors_r = [ False, False, False, True, True, True ]
+ random.shuffle (colors_r)
+ colors = ([ False ] + colors_r[0:3] + [ None, None, None, None ]
+ + colors_r[3:6] + [ True ])
+ add_candle_circle ((1500, 2000), 450, pi + pi / 24, pi / 12, colors, 2)
+ # Glasses.
+ self.glasses = [ ]
+ def add_glass (pos):
+ glass = RoundObstacle (40, 0)
+ glass.pos = pos
+ self.glasses.append (glass)
+ glass = RoundObstacle (40, 0)
+ glass.pos = (3000 - pos[0], pos[1])
+ self.glasses.append (glass)
+ add_glass ((900, 550))
+ add_glass ((1200, 550))
+ add_glass ((1050, 800))
+ add_glass ((1350, 800))
+ add_glass ((900, 1050))
+ add_glass ((1200, 1050))
+ # Cherries.
+ self.plates = [ ]
+ self.cherries = [ ]
+ def add_plate (pos, color):
+ plate = RectangularObstacle ((170, 170), 0)
+ plate.pos = pos
+ plate.angle = 0
+ self.plates.append (plate)
+ cpos = ((-42, -42), (-42, 0), (-42, +42), (0, -21), (0, 21),
+ (42, -42), (42, 0), (42, +42))
+ ccol = [ color ] + 7 * [ None ]
+ random.shuffle (ccol)
+ for p, c in zip (cpos, ccol):
+ cherry = RoundObstacle (20, 0)
+ cherry.pos = (pos[0] + p[0], pos[1] + p[1])
+ cherry.color = c
+ self.cherries.append (cherry)
+ for py in (250, 600, 1000, 1400, 1750):
+ add_plate ((200, py), False)
+ add_plate ((3000 - 200, py), True)
+ # Gifts.
+ self.gifts = [ ]
+ def add_gift (pos, color):
+ gift = RectangularObstacle ((150, 50), 0)
+ gift.pos = pos
+ gift.color = color
+ gift.state = False
+ self.gifts.append (gift)
+ def add_gifts (pos):
+ add_gift ((pos[0] - 176 / 2, pos[1] - 72), False)
+ add_gift ((pos[0] + 176 / 2, pos[1] - 72), True)
+ add_gifts ((600, 0))
+ add_gifts ((1200, 0))
+ add_gifts ((1800, 0))
+ add_gifts ((2400, 0))
+ # Add everything to obstacles.
+ self.obstacles += self.candles
+ self.obstacles += self.glasses
+ self.obstacles += self.cherries
+ self.obstacles += self.gifts
+
diff --git a/host/simu/view/table_eurobot2013.py b/host/simu/view/table_eurobot2013.py
new file mode 100644
index 00000000..889fe369
--- /dev/null
+++ b/host/simu/view/table_eurobot2013.py
@@ -0,0 +1,208 @@
+# simu - Robot simulation. {{{
+#
+# Copyright (C) 2012 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 2013 table."""
+from simu.inter.drawable import Drawable
+from math import pi
+
+YELLOW = '#eaea00'
+RED = '#ff0000'
+BLUE = '#0000e9'
+BLACK = '#1f1b1d'
+WHITE = '#f5fef2'
+TRANS = '#c0c2b5'
+PINK = '#e7baca'
+FLAME = '#dcf000'
+FLAME_OFF = '#9aa800'
+
+colors = { None: WHITE, False: BLUE, True: RED }
+
+class Candle (Drawable):
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ self.model.register (self.update)
+
+ def draw (self):
+ self.reset ()
+ if self.model.pos:
+ self.draw_circle (self.model.pos, self.model.radius,
+ fill = colors[self.model.color])
+ flame = FLAME if not self.model.state else FLAME_OFF
+ self.draw_circle (self.model.pos, self.model.radius * 0.8,
+ fill = flame)
+ Drawable.draw (self)
+
+class Glass (Drawable):
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ self.model.register (self.update)
+
+ def draw (self):
+ self.reset ()
+ if self.model.pos:
+ self.draw_circle (self.model.pos, self.model.radius,
+ fill = BLACK, outline = TRANS)
+ Drawable.draw (self)
+
+class Plate (Drawable):
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ self.model.register (self.update)
+
+ def draw (self):
+ self.reset ()
+ if self.model.pos:
+ self.trans_translate (self.model.pos)
+ w, h = self.model.dim
+ w, h = w/2, h/2
+ self.draw_rectangle ((-w, -h), (w, h), fill = PINK)
+ self.draw_rectangle ((-w + 22, -h + 22), (w - 22, h - 22),
+ fill = PINK)
+ Drawable.draw (self)
+
+class Cherry (Drawable):
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ self.model.register (self.update)
+
+ def draw (self):
+ self.reset ()
+ model = self.model
+ if model.pos:
+ self.draw_circle (model.pos, model.radius,
+ fill = colors[model.color])
+ Drawable.draw (self)
+
+class Gift (Drawable):
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ self.model.register (self.update)
+
+ def draw (self):
+ self.reset ()
+ if self.model.pos:
+ self.trans_translate (self.model.pos)
+ w, h = self.model.dim
+ if not self.model.state:
+ self.draw_rectangle ((-w/2, -11), (w/2, 80),
+ fill = colors[self.model.color])
+ self.draw_rectangle ((-w/2, 80), (w/2, 91), fill = WHITE)
+ else:
+ self.draw_rectangle ((-w/2, -11), (w/2, 11),
+ fill = colors[self.model.color])
+
+class Table (Drawable):
+ """The table and its elements."""
+
+ def __init__ (self, onto, model):
+ Drawable.__init__ (self, onto)
+ self.model = model
+ for e in self.model.candles:
+ Candle (self, e)
+ for e in self.model.glasses:
+ Glass (self, e)
+ for e in self.model.plates:
+ Plate (self, e)
+ for e in self.model.cherries:
+ Cherry (self, e)
+ for e in self.model.gifts:
+ Gift (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, 0), fill = YELLOW)
+ self.draw_rectangle ((0, 0), (3000, 2000), fill = YELLOW)
+ self.draw_rectangle ((-22, 0), (0, 2000), fill = BLUE)
+ self.draw_rectangle ((-22, 2000), (1500, 2000 + 22), fill = BLUE)
+ self.draw_rectangle ((0, 0), (400, 2000), fill = BLUE)
+ self.draw_rectangle ((3000 + 22, 0), (3000, 2000), fill = RED)
+ self.draw_rectangle ((3000 + 22, 2000), (1500, 2000 + 22), fill = RED)
+ self.draw_rectangle ((3000, 0), (3000 - 400, 2000), fill = RED)
+ # Start zones.
+ self.draw_both (self.draw_rectangle, (0, 0), (400, 100), fill = WHITE)
+ self.draw_both (self.draw_rectangle, (0, 0), (390, 90), fill = WHITE)
+ self.draw_both (self.draw_rectangle, (0, 400), (400, 800), fill = WHITE)
+ self.draw_both (self.draw_rectangle, (0, 1200), (400, 1600), fill = WHITE)
+ self.draw_both (self.draw_rectangle, (0, 1900), (400, 2000), fill = WHITE)
+ self.draw_both (self.draw_rectangle, (0, 1910), (390, 2000), fill = WHITE)
+ # Black lines.
+ self.draw_both (self.draw_line, (0, 1400), (460, 1400), fill = BLACK, width = 20)
+ self.draw_both (self.draw_line, (600, 0), (600, 1260), fill = BLACK, width = 20)
+ self.draw_both (self.draw_line, (1200, 0), (1200, 300), fill = BLACK, width = 20)
+ self.draw_line ((740, 1300), (2260, 1300), fill = BLACK, width = 20)
+ self.draw_line ((740, 300), (2260, 300), fill = BLACK, width = 20)
+ self.draw_arc ((450, 1250), 150, outline = BLACK, width = 20, style = 'arc', start = 0)
+ self.draw_arc ((3000 - 450, 1250), 150, outline = BLACK, width = 20, style = 'arc', start = pi/2)
+ self.draw_arc ((750, 1150), 150, outline = BLACK, width = 20, style = 'arc', start = pi/2)
+ self.draw_arc ((3000 - 750, 1150), 150, outline = BLACK, width = 20, style = 'arc', start = 0)
+ self.draw_arc ((750, 450), 150, outline = BLACK, width = 20, style = 'arc', start = pi)
+ self.draw_arc ((3000 - 750, 450), 150, outline = BLACK, width = 20, style = 'arc', start = -pi/2)
+ # Cake.
+ self.draw_arc ((1500, 2000), 500, fill = PINK, start = pi, extent = pi)
+ self.draw_arc ((1500, 2000), 400, start = pi, extent = pi)
+ self.draw_arc ((1500, 2000), 300, start = pi, extent = pi)
+ self.draw_arc ((1500, 2000), 200, start = pi, extent = pi, width = 5, style = 'arc')
+ self.draw_line ((1500, 2000), (1500, 1800), width = 5)
+ # Gifts.
+ def draw_gift (x):
+ self.draw_rectangle ((x - 374/2, -44), (x + 374/2, -22), fill = YELLOW)
+ self.draw_rectangle ((x - 374/2, -94), (x - 374/2 + 22, -44), fill = YELLOW)
+ self.draw_rectangle ((x + 374/2, -94), (x + 374/2 - 22, -44), fill = YELLOW)
+ self.draw_rectangle ((x - 11, -94), (x + 11, -44), fill = YELLOW)
+ draw_gift (600)
+ draw_gift (1200)
+ draw_gift (1800)
+ draw_gift (2400)
+ # Axes.
+ self.draw_line ((0, 200), (0, 0), (200, 0), arrow = 'both')
+ # Beacons.
+ self.draw_both (self.draw_rectangle, (-22, 2000 + 22), (-22 - 80, 2000 + 22 + 80), fill = BLACK)
+ self.draw_both (self.draw_rectangle, (-22, 1000 - 40), (-22 - 80, 1000 + 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_eurobot2013 as model
+ app = Inter ()
+ m = model.Table ()
+ Table (app.table_view, m)
+ app.mainloop ()