From a32cf498ca953e0ebc0558958977ecd37fc741a5 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 15 Apr 2013 22:24:42 +0200 Subject: host/simu, host/simu/robots/apbirthday: add plate loading simulation --- host/simu/robots/apbirthday/view/robot.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'host/simu/robots/apbirthday/view/robot.py') diff --git a/host/simu/robots/apbirthday/view/robot.py b/host/simu/robots/apbirthday/view/robot.py index cb489fb0..e4153232 100644 --- a/host/simu/robots/apbirthday/view/robot.py +++ b/host/simu/robots/apbirthday/view/robot.py @@ -23,19 +23,22 @@ # }}} """APBirthday robot view.""" import simu.inter.drawable +from simu.view.table_eurobot2013 import PINK, colors COLOR_ROBOT = '#000000' COLOR_AXES = '#202040' class Robot (simu.inter.drawable.Drawable): - def __init__ (self, onto, position_model, cake_arm_model): + def __init__ (self, onto, position_model, cake_arm_model, cannon_model): """Construct and make connections.""" simu.inter.drawable.Drawable.__init__ (self, onto) self.position_model = position_model self.position_model.register (self.__position_notified) self.cake_arm_model = cake_arm_model self.cake_arm_model.register (self.update) + self.cannon_model = cannon_model + self.cannon_model.register (self.update) def __position_notified (self): """Called on position modifications.""" @@ -49,6 +52,20 @@ class Robot (simu.inter.drawable.Drawable): if self.pos is not None: self.trans_translate (self.pos) self.trans_rotate (self.angle) + # Draw plate. + plate = self.cannon_model.plate + f = self.cannon_model.arm_cyl.pos + if plate is not None: + self.draw_rectangle ((-108 - f * 170, 85), (-108, -85), + fill = PINK) + self.draw_rectangle ((-108 - f * 148, 85 - 22), + (-108 - f * 22, -85 + 22), fill = PINK) + for c in plate.cherries: + if c.pos: + self.draw_circle ((-108 - f * (c.pos[0] + 85), + c.pos[1]), c.radius, fill = colors[c.color]) + self.draw_rectangle ((-108 - f * 170, 85), + (-108 - f * 170 - (1 - f) * 22, -85), fill = PINK) # Draw robot body. self.draw_polygon ((102, 140), (102, -140), (-108, -140), (-108, 70), (-58, 140), fill = COLOR_ROBOT) -- cgit v1.2.3