Exemple #1
0
    def __init__(self, draw_gui=False, intrusion=None):
        """ Ctor """

        object.__init__(self)

        self._has_gui = draw_gui
        self._gui_size = 0
        self._frame_count = 0
        self._gui_output = None

        # Initialise background (500 x 500)
        self._background = [[
            Rgb(DEFAULT_BG_R, DEFAULT_BG_G, DEFAULT_BG_B)
            for _ in range(0, 500)
        ] for _ in range(0, 500)]
        self._turtles = {}

        self._id_counter = 0
        self._update_interval = None

        rospy.set_param("background_r", DEFAULT_BG_R)
        rospy.set_param("background_g", DEFAULT_BG_G)
        rospy.set_param("background_b", DEFAULT_BG_B)

        rospy.loginfo("Starting turtle frame with parent node %s",
                      rospy.get_name())

        trt_x = random.randrange(0, self.get_width())
        trt_y = random.randrange(0, self.get_height())

        self._spawn_turtle(trt_x, trt_y)

        # Colouring the background
        # Window is 500 x 500, starting bottom left at 0,0 and ending top right at 499,499

        # Top left: Pastel purple
        self._draw_area(Rgb.pastel_purple(), Point(0, 250), Point(249, 499))
        # Top right: Pastel yellow
        self._draw_area(Rgb.pastel_yellow(), Point(250, 250), Point(499, 499))
        # Bottom left: Pastel green
        self._draw_area(Rgb.pastel_green(), Point(0, 0), Point(249, 249))
        # Bottom right: Pastel blue
        self._draw_area(Rgb.pastel_blue(), Point(250, 0), Point(499, 249))
        # Intrusion zone (middle): Red
        self._draw_red(intrusion)

        # Initialise GUI (if requested)
        self._redraw()

        # Initialise update timer (16 msec)
        self._update_interval = rospy.Duration(0.016)
        rospy.Timer(self._update_interval, self._update_turtles)
Exemple #2
0
    def _get_output_letter(rgb):
        """ Produce a letter for the given Rgb. Returns "?" for unknown colours. """

        if rgb == Rgb.pastel_purple():
            return "p"
        elif rgb == Rgb.pastel_yellow():
            return "y"
        elif rgb == Rgb.pastel_green():
            return "g"
        elif rgb == Rgb.pastel_blue():
            return "b"
        elif rgb == Rgb.strong_red():
            return " "

        return "?"