Example #1
0
    def draw_2dprojection_universe(self, U: u.Universe, grid=False):
        """
        Given a universe object, draw all possible objects on the screen.
        This is done by calling draw_2dprojection_body object for each body object.
        """

        if U.wall != None:
            self.screen.fill(col.rgb_inverse(self.colour))

            w, h = self.dims
            x_min = self.offset[0]
            y_min = self.offset[1]
            x_max = x_min + w
            y_max = y_min + h

            #rt ==> top tight
            xrt = self.get_x_pix(U.wall)
            yrt = self.get_y_pix(U.wall)

            other_side = -U.wall
            #lb ==> bottom left
            xlb = self.get_x_pix(other_side)
            ylb = self.get_y_pix(other_side)

            if xrt > x_max:
                xrt = w
            if yrt < y_min:
                yrt = 0
            if xlb < x_min:
                xlb = 0
            if ylb > y_max:
                ylb = h

            pygame.draw.polygon(self.screen, self.colour, [(xlb, ylb),
                                                           (xlb, yrt),
                                                           (xrt, yrt),
                                                           (xrt, ylb)])

        else:
            self.screen.fill(self.colour)

        self.draw_trails(U)

        for body in U.bodies:
            if isinstance(body, b.Body):
                self.draw_2dprojection_body(body)

        if grid:
            line_colour = col.rgb_inverse(self.colour)
            centre = self.default_centre()
            w, h = self.dims

            pygame.draw.line(self.screen, line_colour, (centre[0], 0),
                             (centre[0], h - 1), 2)
            pygame.draw.line(self.screen, line_colour, (0, centre[1]),
                             (w - 1, centre[1]), 2)
Example #2
0
    def write_title_message(self, text: str, background=True, offset=(0, 0)):
        back_colour = None
        if background:
            back_colour = col.rgb_inverse(self.text_colour)

        self.write_message(text,
                           font_size=self.title_size,
                           centre=(True, True),
                           text_colour=self.text_colour,
                           background_colour=back_colour,
                           offset=offset)
Example #3
0
    def draw_tracking_label(self, U: u.Universe):
        """
        Draw a label for what body is currently being tracked.
        If the body has a name, use that instead of the id.
        """

        msg = ""
        colour = None

        if self.track_id < 0:
            ## dont draw a label
            if self.default_message == None:
                pass
            else:
                msg = self.default_message
            colour = col.rgb_inverse(self.colour)

        elif self.track_id == 0:
            msg = "Centre of Mass"
            colour = col.rgb_inverse(self.colour)

        else:
            body = U.get_body(self.track_id)
            msg = body.get_name()

            colour = body.colour

        if self.show_zoom:
            zoom = self.default_scale / self.scale
            if zoom != 1.0:
                if len(msg) != 0:
                    msg += ",   " + "Zoom: x" + str(zoom)
                else:
                    msg = "Zoom: x" + str(zoom)

        self.write_label(msg, colour)
Example #4
0
    def __init__(self,
                 width=800,
                 height=600,
                 scale=1.,
                 colour=col.white,
                 text_colour=col.black,
                 label_size=50,
                 title_size=100,
                 msg=None):

        self.dims = (width, height)
        self.screen = pygame.display.set_mode(self.dims)
        pygame.display.set_caption("Simulation")

        self.colour = colour
        self.default_scale = scale
        self.scale = scale

        self.default_message = msg
        self.text_colour = text_colour
        self.label_size = label_size
        self.title_size = title_size

        self.screen_centre = self.default_centre()
        self.offset = (0, 0)
        self.track_id = -1

        self.centre = None
        self.proj = None

        self.show_zoom = False
        self.updated_default_centre = False

        # update the screen to say 'loading'
        self.write_label("Loading...", col.rgb_inverse(self.colour), True,
                         (True, True))
        pygame.display.update()
Example #5
0
            screen.update_origin_tracking(universe)
            screen.draw_2dprojection_universe(universe, grid=pan)
            screen.draw_tracking_label(universe)
            pause_drawn = True
        except Exception as e:
            error = True
            error_name = str(e)

    if not error and not wait:
        if start_screen:
            screen.write_title_message("Press SPACE to begin")

        elif paused:
            if pan:
                screen.write_label("PAN CAMERA",
                                   colour.rgb_inverse(screen.colour), True,
                                   (True, False))
            else:
                screen.write_label("Paused", colour.rgb_inverse(screen.colour),
                                   True, (True, True))

        elif help:
            screen.write_label(help_comment,
                               colour.rgb_inverse(screen.colour),
                               True, (False, True),
                               size=50,
                               offset=(50, 0))

        else:
            if control:
                screen.write_label("CONTROL",