def test_gravity(self): """Test Moon object creation from text""" # 1. Create two moons ganymede = moon.Moon(text='<x=3, y=4, z=7>') callisto = moon.Moon(text='<x=5, y=4, z=2>') # 2. Calculate the effects of gravity ganymede.apply_gravity(callisto) # 3. Check the change in velocities self.assertEqual(ganymede.delta, [+1, 0, -1]) self.assertEqual(callisto.delta, [-1, 0, +1]) # 4. Apply these changes in velocities ganymede.update_velocity_and_position() callisto.update_velocity_and_position() # 5. Check the updated velocities and positions self.assertEqual(ganymede.pos, (4, 4, 6)) self.assertEqual(ganymede.vel, (1, 0, -1)) self.assertEqual(ganymede.delta, [0, 0, 0]) self.assertEqual(ganymede.stopped(), False) self.assertEqual(callisto.pos, (4, 4, 3)) self.assertEqual(callisto.vel, (-1, 0, 1)) self.assertEqual(callisto.delta, [0, 0, 0]) self.assertEqual(callisto.stopped(), False)
def __init__(self, width, height): self.mWidth = width self.mHeight = height self.mBlueSky = sky.Sky(self.mWidth, self.mHeight) self.mGround = ground.Ground(self.mWidth, self.mHeight) self.mMountain = mountain.Mountain(self.mWidth, self.mHeight) self.mMoon = moon.Moon(self.mWidth, self.mHeight) self.mWater = water.Water(self.mWidth, self.mHeight) self.mHouse = house.House(self.mWidth, self.mHeight) self.mCloud = cloud.Cloud(self.mWidth, self.mHeight) self.mBird = bird.Bird(self.mWidth, self.mHeight)
def test_text_init(self): """Test Moon object creation from text""" # 1. Create default Moon object mymoon = moon.Moon(text='<x=-1, y=0, z=2>') # 2. Make sure it has the default values self.assertEqual(mymoon.pos, (-1, 0, 2)) self.assertEqual(mymoon.vel, (0, 0, 0)) self.assertEqual(mymoon.delta, [0, 0, 0]) # 3. Check methods self.assertEqual(mymoon.stopped(), True) self.assertEqual(mymoon.energy(), 0) self.assertEqual( str(mymoon), 'pos=<x= -1, y= 0, z= 2>, vel=<x= 0, y= 0, z= 0>, nrg= 0')
def test_value_init(self): "Test Moon object creation with values" # 1. Create Panel object with values mymoon = moon.Moon(pos=(2, -1, -3), vel=(3, -2, -1)) # 2. Make sure it has the specified values self.assertEqual(mymoon.pos, (2, -1, -3)) self.assertEqual(mymoon.vel, (3, -2, -1)) self.assertEqual(mymoon.delta, [0, 0, 0]) # 3. Check methods self.assertEqual(mymoon.stopped(), False) self.assertEqual(mymoon.energy(), 36) self.assertEqual( str(mymoon), 'pos=<x= 2, y= -1, z= -3>, vel=<x= 3, y= -2, z= -1>, nrg= 36')
def __init__(self, text=None): # 1. Start with very few moons self.moons = [] self.zeroes = [0, 0, 0] # 2. If we have text, create moons and add to list if text is not None: # 3. Loop for each line of text for line in text: # 4. Create a new orbiting body body = moon.Moon(text=line) # 5. Add this moon to the list self.moons.append(body)
def __init__(self, width_factor, seed=time.time(), prnt=False): '''Initialize random variables and generate image''' if width_factor <= 0: print("Whoops! First paramater must be greater than zero") exit(-1) ##-=-=-=- Set Random Seed -=-=-=-=-=-=-=-=-=-## self.rand_seed = int(seed) random.seed(self.rand_seed) ##-=-=-=- Tweakable Values -=-=-=-=-=-=-=-=-=## self.num_ranges = 3 # Number of mountain ranges to be generated self.num_sines = 10 # Number of sin values generated for each mountain range self.image_height = 150 # Consider this the amount of "detail" in the mountains self.shadow_angle = 2.5 # The angle of the shadow on the mountains ##-=-=-=- Constant Values -=-=-=-=-=-=-=-=-=## self.constant = 30 # Overall amplitude of superpositioned waves self.k = 0.04 # Streching factor of mountains self.pnf = perlin.SimplexNoise() # Initialize perlin noise creator self.sky_color = [30, 30, 40] # Set Color of sky and mountains self.color = [ random.randint(0, 150), random.randint(0, 150), random.randint(0, 150) ] self.moon = moon.Moon(15, self.rand_seed) ##-=-=-=- Programatically Set Values -=-=-=-## self.image_width = int(width_factor * self.image_height) self.data = list # Stored variables of sine wave functions self.output = [[ tuple(self.sky_color) for x in range(self.image_width) ] for y in range(self.image_height)] self.moon_location = random.randint(0, self.image_width - 10) ##-=-=-=- Creation -=-=-=-=-=-=-=-=-=-=-=-=-## self.pnf.randomize() # Randomize perlin noise self.generate_ranges() # Generate variables for sine functions self.create_moon(self.moon_location, 2) self.create_scene() # Assign values to pixels self.show_image() if prnt: print(self)
def store_globals(self): """We store references to some things here that are needed all over the game.""" # number of levels self.numlevels = len(leveldata.ALLDATA) # the main sprites self.moon = moon.Moon(self) self.rocket = rocket.Rocket(self) self.pbar = powerbar.Powerbar(self) self.gbar = gravitybar.Gravitybar(self) # text 'gravity' and 'power' for status bars are stored as # additional sprites self.pbartext = fontsprite.FontSprite(self.barfont, 'power', fontsprite.PBARLOC) self.gbartext = fontsprite.FontSprite(self.barfont, 'gravity', fontsprite.GBARLOC) # some states needed by many objects self.hitmoon = False self.rktdead = False # dead if gone off-screen self.hitasteroid = False # number of rockets destroyed so far in game self.numdestroyed = 0 self.destroyedtext = fontsprite.FontSprite(self.destfont, '{0}{1}'.format\ (fontsprite.DTEXT,0), fontsprite.DESTLOC) # collision functions # rocket with asteroids (scaled rect collision) self.collide_roid = pygame.sprite.collide_rect_ratio(Game.\ CRECTROID) # rocket with moon ('pixel perfect' collision) self.collide_moon = pygame.sprite.collide_mask # scroller handles moving screen and sprites etc self.scroller = scrolling.Scroller(self)
def __init__(self, jdn): self.jdn = jdn self.cylenian_date = cylenian.CylenianDate(self.jdn) self.gregorian_date = gregorian.GregorianDate(self.jdn) self.moon = moon.Moon(self.jdn)
import numpy import sys import moon def lcm(a, b): return abs(a * b) // math.gcd(a, b) moons = [] for line in sys.stdin.read().split('\n'): if len(line): print(line) xyz = [x.split('=')[1] for x in line.strip('<>').split(',')] moons.append(moon.Moon(xyz[0], xyz[1], xyz[2])) print('\n'.join([str(x) for x in moons])) original = copy.deepcopy(moons) count = 0 while True: for m in moons: for o in moons: m.update_velocity(o) for m in moons: m.apply_velocity() count += 1
sun.print(start_secs, start_secs + 3600*24) if rain != None: rain.print(start_secs, start_secs + 3600*24) if moon != None: moon.print(start_secs, start_secs + 3600*24) if seatemp != None: seatemp.print(start_secs, start_secs + 3600*24) if tide != None: tide.print(start_secs, start_secs + 3600*24) if swell_wind != None: swell_wind.print(start_secs, start_secs + 3600*24) print("") location = "sydney" locations = ["sydney", "newcastle", "wollongong", "frazer_beach", "boat_harbour"] if len(sys.argv) >= 1 and sys.argv[1] in locations: location = sys.argv[1] suni = sun.Sun(willy_uri_get("sun", location)) raini = rain.Rain(willy_uri_get("rain", location)) mooni = moon.Moon(willy_uri_get("moon", location)) seatempi = seatempnet.Seatempnet(seatemp_page[location]) tidei = tide.Tide(willy_uri_get("tide", location)) swelli = swell.Swell(willy_uri_get("swell", location)) windi = wind.Wind(willy_uri_get("wind", location)) swell_windi = swell_wind.SwellWind(swelli.get(), windi.get()) for i in range(0, 7): secs = now + 3600 * 24 * i print_a_day(secs, suni, raini, mooni, seatempi, tidei, swell_windi)
import moon, mars, util rpc_handler = util.XMLRPCHandler() #_earth = earth.Earth() _moon = moon.Moon() _mars = mars.Mars() #@rpc_handler.register('earth.altitude') #def earth_altitude(pos, lon=None): # return util.for_positions(_earth.altitude, pos, lon) #@rpc_handler.register('earth.radius') #def earth_radius(pos, lon=None): # return util.for_positions(_earth.radius, pos, lon) @rpc_handler.register('moon.altitude') def moon_altitude(pos, lon=None): return util.for_positions(_moon.altitude, pos, lon) @rpc_handler.register('moon.radius') def moon_radius(pos, lon=None): return util.for_positions(_moon.radius, pos, lon) @rpc_handler.register('mars.altitude') def mars_altitude(pos, lon=None): return util.for_positions(_mars.altitude, pos, lon)