Untitled

mail@pastecode.io avatar
unknown
python
22 days ago
6.2 kB
2
Indexable
Never
import pygame, math


def draw_planet(centre, scalar, planets, WINDOW):
    for obj in planets:
        if obj.name != "Sun":	#draws all of the planets and orbits except the sun
            pygame.draw.circle(WINDOW, (200, 200, 200), centre,
                               (obj.orbital_radius / (scalar * 10000000)), 1)
            pygame.draw.circle(WINDOW, obj.colour,
                               (centre[0] + obj.get_planet_position_x(scalar),
                                centre[1] + obj.get_planet_position_y(scalar)),
                               (obj.planet_radius / (scalar * 10000)))
        else:	#draws just the sun
            pygame.draw.circle(WINDOW, obj.colour, (centre[0], centre[1]),
                               (obj.planet_radius / (scalar * 10000)))

def draw_box(font1, font3, boxes, num_boxes, WINDOW):
    for obj in boxes[0:num_boxes]:
        if obj.__class__.__name__ == "box":
            WINDOW.blit(font1.render(obj.input_text, True, (255, 255, 255)),
                        (obj.xcoord + 80 -
                         (font1.render(obj.input_text, True,
                                       (255, 255, 255)).get_width() / 2),
                         obj.ycoord + (obj.height / 2) -
                         (font1.render(obj.input_text, True,
                                       (255, 255, 255)).get_height() / 2)))
            pygame.draw.rect(WINDOW, obj.colour,
                             (obj.xcoord, obj.ycoord, obj.width, obj.height),
                             2, 10)  #draws text box
            WINDOW.blit(font3.render(obj.name, True, (255, 255, 255)),
                        (obj.xcoord + 80 -
                         (font3.render(obj.name, True,
                                       (255, 255, 255)).get_width() / 2),
                         obj.ycoord - 30))
            pygame.draw.rect(WINDOW, obj.colour,
                             (obj.xcoord, obj.ycoord -
                              (obj.height / 2), obj.width, obj.height / 2), 2,
                             10)

        else:
            button_render = font1.render(obj.text, True, "black")
            pygame.draw.rect(WINDOW,
                             obj.colour,
                             (obj.xcoord, obj.ycoord, obj.width, obj.height),
                             border_radius=10)
            pygame.draw.rect(WINDOW, "black", (obj.xcoord + 1, obj.ycoord + 1,
                                               obj.width - 2, obj.height - 2),
                             2, 10)
            WINDOW.blit(button_render,
                        (obj.xcoord + (obj.width / 2) -
                         (button_render.get_width() / 2), obj.ycoord +
                         (obj.height / 2) - (button_render.get_height() / 2)))


def travel_time(planets, time_scalar):
    for obj in planets:
        if obj.name != "Sun":
            obj.angle += 2 * time_scalar * (math.pi) / obj.orbital_period
            if obj.angle >= 2 * math.pi:
                obj.angle -= 2 * math.pi


def draw_plot(centre, scalar, home_planet, target_planet, WINDOW):
    #calculates dimensions of ellipse
    semi_major_axis = int(
        (home_planet.orbital_radius + target_planet.orbital_radius) / 2)
    eccentricity = (target_planet.orbital_radius - home_planet.orbital_radius
                    ) / (target_planet.orbital_radius +
                         home_planet.orbital_radius)
    semi_minor_axis = int(semi_major_axis * math.sqrt(1 - eccentricity**2))

    ellipse_surface = pygame.Surface(
        (semi_minor_axis / (scalar * 5000000), semi_major_axis /
         (scalar * 5000000)), pygame.SRCALPHA)

    # Draw partial ellipse on the surface
    pygame.draw.arc(ellipse_surface, (0, 255, 0),
                    (0, 0, semi_minor_axis /
                     (scalar * 5000000), semi_major_axis / (scalar * 5000000)),
                    0.5 * math.pi, 1.5 * math.pi, 1)

    # Rotate the surface
    ellipse_surface_rotated = pygame.transform.rotate(
        ellipse_surface, math.degrees((0.5 * math.pi) - home_planet.angle))

    # Blit the rotated surface onto the screen
    if home_planet.angle < 0.5 * math.pi:
        WINDOW.blit(ellipse_surface_rotated,
                    (centre[0] + home_planet.get_planet_position_x(scalar) -
                     ellipse_surface_rotated.get_width() +
                     abs(semi_minor_axis * math.sin(home_planet.angle)) /
                     (scalar * 10000000),
                     centre[1] + home_planet.get_planet_position_y(scalar) -
                     ellipse_surface_rotated.get_height() +
                     abs(semi_minor_axis * math.cos(home_planet.angle)) /
                     (scalar * 10000000)))
    elif home_planet.angle < math.pi:
        WINDOW.blit(ellipse_surface_rotated,
                    (centre[0] + home_planet.get_planet_position_x(scalar) -
                     abs(semi_minor_axis * math.sin(home_planet.angle)) /
                     (scalar * 10000000),
                     centre[1] + home_planet.get_planet_position_y(scalar) -
                     ellipse_surface_rotated.get_height() +
                     abs(semi_minor_axis * math.cos(home_planet.angle)) /
                     (scalar * 10000000)))
    elif home_planet.angle < 1.5 * math.pi:
        WINDOW.blit(ellipse_surface_rotated,
                    (centre[0] + home_planet.get_planet_position_x(scalar) -
                     abs(semi_minor_axis * math.sin(home_planet.angle)) /
                     (scalar * 10000000),
                     centre[1] + home_planet.get_planet_position_y(scalar) -
                     abs(semi_minor_axis * math.cos(home_planet.angle)) /
                     (scalar * 10000000)))
    elif home_planet.angle < 2 * math.pi:
        WINDOW.blit(ellipse_surface_rotated,
                    (centre[0] + home_planet.get_planet_position_x(scalar) -
                     ellipse_surface_rotated.get_width() +
                     abs(semi_minor_axis * math.sin(home_planet.angle)) /
                     (scalar * 10000000),
                     centre[1] + home_planet.get_planet_position_y(scalar) -
                     abs(semi_minor_axis * math.cos(home_planet.angle)) /
                     (scalar * 10000000)))
Leave a Comment