def crear_cuerpos_celestes(self):
        sun = BaseObject(self.default_planet_img, self.sun_position)

        planetas = [
            sun,
            Planet(self.default_planet_img, self.sun_position, 250),
            Planet(self.default_planet_img, self.sun_position, 500),
        ]

        return planetas
Exemple #2
0
 def testSimple(self):
     ps = PlanetarySystem()
     ps.append(Planet(1.0, 1.0, 0.1))
     ps.append(Planet(-1.0, 1.0, 0.2))
     ps.append(Planet(1.2, 3.4, math.pi / 10))
     ps.tick()
     self.assertAlmostEqual(ps[0].theta(), math.pi / 4 + 0.1)
     self.assertAlmostEqual(ps[1].theta(), 3 * math.pi / 4 + 0.2)
     for i in range(19):
         ps.tick()
     self.assertAlmostEqual(ps[2].x(), 1.2)
     self.assertAlmostEqual(ps[2].y(), 3.4)
Exemple #3
0
 def testSimple(self):
     p1 = Planet(5.0, 0.0, 0.1)
     self.assertAlmostEqual(p1.rho(), 5.0)
     self.assertAlmostEqual(p1.theta(), 0.0)
     p1.tick()
     self.assertAlmostEqual(p1.rho(), 5.0)
     self.assertAlmostEqual(p1.theta(), 0.1)
Exemple #4
0
def update_planets(planets, center_on='sun', delta=1):
    for p1, p2 in combinations(planets.values(), 2):
        Planet.compute_forces(p1, p2)

    deleted = []

    sun_pos = planets[center_on].pos.copy()
    sun_vel = planets[center_on].vel.copy()
    for k, p in planets.items():
        p.update_planet(delta)

        p.pos = p.pos - sun_pos
        p.vel = p.vel - sun_vel

    for k in deleted:
        del planets[k]
Exemple #5
0
def simulate(args, center_on='sun', initial_frame=0):
    random.seed(args.seed)

    days_to_pass = 600
    days = int(5 * days_to_pass)
    days_elapsed = 0
    frame_i = initial_frame

    planets = initialize_planets(args)

    planets['rogue'] = Planet.produce_rogue(
        days_to_pass,
        args.solar_mass
    )

    pbar = tqdm(total=days)
    fig = plt.figure(figsize=(6, 6))

    while days_elapsed < days:
        for j in range(args.days_per_frame * 24):
            update_planets(planets, center_on=center_on, delta=3600)

        plot_planets(fig, planets, args, frame_i, days_elapsed)

        frame_i += 1
        days_elapsed += args.days_per_frame
        pbar.update(args.days_per_frame)

    pbar.close()

    return frame_i
 def testSimple(self):
     p1 = Planet(5.0, 0.0, 0.1)
     self.assertAlmostEqual(p1.rho(), 5.0)
     self.assertAlmostEqual(p1.theta(), 0.0)
     p1.tick()
     self.assertAlmostEqual(p1.rho(), 5.0)
     self.assertAlmostEqual(p1.theta(), 0.1)
Exemple #7
0
 def __init__(self):
     self.earth = Planet("Earth")
     self.aarakis = Planet("Aarakis")
     self.alpha_centauri = Planet("Alpha Centauri II")
     self.coruscant = Planet("Coruscant")
     self.eden_prime = Planet("Eden Prime")
     self.titan = Planet("Titan")
     self.vulcan = Planet("Vulcan")
Exemple #8
0
def create_dataframe(time):
    """
    time: animation time in years (float)

    Returns 
    Dataframe with planet coordinates in reference frame of the ecliptic
    for <time> years. Dataframe columns include: 
    x, y, z: coordinates
    time: timestamp (integers for now, that are used to generate animation frames)
    Planet: name of the planet
    """
    df1 = pd.read_csv('data/planet_orbital_elements.csv')
    df2 = pd.read_csv('data/planet_elements.csv')

    df = df1.merge(df2, on='name')    

    dataframes = []
    for _, row in df.iterrows():
        logging.info("Creating dataframe for Planet {}".format(row['name']))
        planet = Planet(aphelion=row['aphelion_AU'], 
                        perihelion=row['perihelion_AU'], 
                        Omega = row['Omega_deg'],
                        i = row['inclination_deg'],
                        w = row['arg_periapsis_deg'],
                        orbital_period=row['period_years'],
                        time=time)
    
        logging.info("Calculating coordinates")
        planet_coordinates = planet.get_coordinates()
        planet_coordinates['timestamp'] = pd.Series([time for time in range(len(planet_coordinates))])

        planet_coordinates['Planet'] = row['name']
        #planet_coordinates['size'] = row.diameter_earths/10.0

        dataframes.append(planet_coordinates)

    all_planet_coordinates = pd.concat(dataframes)

    return all_planet_coordinates
class PlanetTest(unittest.TestCase):
    def setUp(self):
        self.p1 = Planet(5.0, 0.0, 0.1)

    def testInitial(self):
        self.assertAlmostEqual(self.p1.rho(), 5.0)
        self.assertAlmostEqual(self.p1.theta(), 0.0)

    def testOneMove(self):
        self.p1.tick()
        self.assertAlmostEqual(self.p1.rho(), 5.0)
        self.assertAlmostEqual(self.p1.theta(), 0.1)
Exemple #10
0
 def claim_planet(self, planet):
     self.planets[planet] = Planet(planet, 'Eden', 3)
     return ' Found {0}'.format(planet)
 def setUp(self):
     self.p1 = Planet(5.0, 0.0, 0.1)
 def setUp(self):
     self.ps = PlanetarySystem()
     self.ps.append(Planet(1.0, 1.0, 0.1))
     self.ps.append(Planet(-1.0, 1.0, 0.2))
     self.ps.append(Planet(1.2, 3.4, math.pi / 10))
     self.ps.append(SpaceShip(10, 0, 0.1, 0.1))
Exemple #13
0
robot_speak = bacon.Font('LCD_Solid.ttf', 14)

# music
music = bacon.Sound('farewell.ogg', stream=True)

# sets ranges for the main game icons at the bottom of the screen
battery_range = {'x1': 183, 'x2': 233, 'y1': 486, 'y2': 540}
cargo_range = {'x1': 267, 'x2': 339, 'y1': 486, 'y2': 540}
market_range = {'x1': 363, 'x2': 486, 'y1': 486, 'y2': 540}
money_range = {'x1': 460, 'x2': 540, 'y1': 486, 'y2': 540}
depart_range = {'x1': 555, 'x2': 630, 'y1': 486, 'y2': 540}

planet_master = []
planet_locator = []
for item in planet_list:  #create master planet list
    planet_master.append(Planet(item[0], item[1], item[2], merch_list.pop(0)))
    planet_locator.append((item[1], item[2]))

myplayer = Player("Hobart Killjoy", "defiant", 10000, 0, 213,
                  196)  # initialize player class
myship = Ship("Defiant", 10, 10000, 50)  #initialize ship class
myship.fuel = 100  # set fuel to 100 for start
line_height = 25  # for planet font

#initalize music
music_voice = bacon.Voice(music, loop=True)
# star music at start of game
music_voice.play()

x = 360  #initialize player start position
y = 300
Exemple #14
0
def initialize_planets(args):
    planets = {}
    planets['sun'] = Planet(
        'sun',
        Point(0., 0.),
        Point(0., 0.),
        mass=1.989e30,
        color='yellow'
    )
    planets['mercury'] = Planet.in_orbit_of(
        planets['sun'],
        'mercury',
        radius=57.91e9,
        mass=3.285e23,
        color='gray',
        days_per_frame=args.days_per_frame
    )
    planets['venus'] = Planet.in_orbit_of(
        planets['sun'],
        'venus',
        radius=108.2e9,
        mass=4.867e24,
        color='white',
        days_per_frame=args.days_per_frame
    )
    planets['earth'] = Planet.in_orbit_of(
        planets['sun'],
        'earth',
        radius=149.6e9,
        mass=5.972e24,
        color='c',
        days_per_frame=args.days_per_frame
    )
    planets['mars'] = Planet.in_orbit_of(
        planets['sun'],
        'mars',
        radius=227.9e9,
        mass=6.39e23,
        color='r',
        days_per_frame=args.days_per_frame
    )
    planets['jupiter'] = Planet.in_orbit_of(
        planets['sun'],
        'jupiter',
        radius=778.5e9,
        mass=1.898e27,
        color='brown',
        days_per_frame=args.days_per_frame
    )
    planets['saturn'] = Planet.in_orbit_of(
        planets['sun'],
        'saturn',
        radius=1.434e12,
        mass=5.68e26,
        color='yellow',
        days_per_frame=args.days_per_frame
    )
    '''
    planets['moon'] = Planet.in_orbit_of(
        planets['earth'],
        'moon',
        radius=3.8e8,
        mass=7.35e22,
        color='white',
        days_per_frame=args.days_per_frame
    )
    '''

    return planets
Exemple #15
0
# -*- coding: utf-8 -*-
# calculate Sun longitude according to Paul Schlyter formulas
from tools import *
from planets import Planet
year, month, day = (1990, 4, 19)
for body in ('Sun', 'Moon', 'Mercury', 'Venus', 'Mars',
               'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto'):
    
    planet = Planet(body, year, month, day).position()
    print body, planet