def main(): t = 0 milky_way = Galaxy( num_stars=NUM_STARS_MILKY_WAY, pos=vector(-5, 0, 0) * DIST_SCALE, vel=vector(0, 0, 0), radius=MAX_ORBITAL_RADIUS, thickness=MILKY_WAY_GALAXY_THICKNESS, color=vector(0.9, 0.9, 1) ) andromeda = Galaxy( num_stars=NUM_STARS_ANDROMEDA, pos=vector(3, 0, 0) * DIST_SCALE, vel=vector(0, 3, 0), radius=MAX_ORBITAL_RADIUS, thickness=ANDROMEDA_GALAXY_THICKNESS, color=vector(0, 0.5, 1) ) while True: rate(100) mag_difference = milky_way.pos.mag - andromeda.pos.mag for i in range(len(milky_way.stars)): star = milky_way.stars[i] star.vel += accel(star, andromeda) * dt star.vel += accel(star, milky_way) * dt star.pos += star.vel * dt # if(mag_difference == -6+18): # star.obj.color = vector(1, 0.5, 0) if(andromeda.pos.mag < 1.1920057081525512e+20): star.obj.color = vector(1, 0.5, 0) andromeda_mask = np.zeros(len(andromeda.stars)) for star in andromeda.stars: star.vel += accel(star, milky_way) * dt star.vel += accel(star, andromeda) * dt star.pos += star.vel * dt # if(mag_difference < -6+18 and mag_difference > -5e+18): # star.obj.color = vector(1, 0.5, 0) if(andromeda.pos.mag < 1.1920057081525512e+20): star.obj.color = vector(1, 0.5, 0) milky_way.vel += accel(milky_way, andromeda) * dt milky_way.pos += milky_way.vel * dt andromeda.vel += accel(andromeda, milky_way) * dt andromeda.pos += andromeda.vel * dt t += dt
def main(): ferengi = Planet(distance=500, speed=-1) betasoide = Planet(distance=2000, speed=-3) vulcan = Planet(distance=1000, speed=5) star_trek_galaxy = Galaxy([ferengi, betasoide, vulcan]) draft_days = 0 perfect_days = 0 rainy_day = 0 most_rain_day = -1 most_rain_perimeter = 0 for day in range(3650): alignment = star_trek_galaxy.planets_are_aligned(day) if alignment is PlanetsPosition.ALIGNED_WITH_THE_SUN: draft_days += 1 elif alignment is PlanetsPosition.ALIGNED_WITH_EACHOTHER: perfect_days += 1 else: # if we are here, planets are forming a polygon (sunsPosition, per) = star_trek_galaxy.calculate_suns_position(day) if sunsPosition is PlanetsPosition.SUN_INSIDE_POLYGON: rainy_day += 1 if per > most_rain_perimeter: most_rain_day = day most_rain_perimeter = per print('Draft:', draft_days) print('Perfect:', perfect_days) print('Rainy:', rainy_day) print('Most rain:', most_rain_day)
def __init__(self, client, *args, **kwargs): logger.debug("Lobby instantiating.") BaseClass.__init__(self, *args, **kwargs) self.setupUi(self) self.client = client #self.client.galacticwarTab.setStyleSheet(util.readstylesheet("galacticwar/galacticwar.css")) self.COLOR_FACTIONS = {} self.mapTransparency = 10 self.AA = True self.rotation = True self.stars = 25 self.GWOptions = GWOptions(self) self.GWOptions.loadSettings() self.client.galacticwarTab.layout().addWidget(self) self.downloader = QNetworkAccessManager(self) self.downloader.finished.connect(self.finishRequest) self.shaderlist = [] self.texturelist = {} self.shaders = {} self.infoPanel = None self.OGLdisplay = None self.galaxy = Galaxy(self) self.channel = None self.initDone = False self.uid = None self.faction = None self.name = None self.rank = None self.credits = 0 self.victories = 0 self.enslavedBy = None self.attacks = {} self.state = ClientState.NONE ## Network initialization self.socket = QtNetwork.QTcpSocket() self.socket.readyRead.connect(self.readFromServer) self.socket.disconnected.connect(self.disconnectedFromServer) self.socket.error.connect(self.socketError) self.blockSize = 0 self.progress = QtGui.QProgressDialog() self.progress.setMinimum(0) self.progress.setMaximum(0)
def run_game(): """ initialize game """ pygame.init() settings = Settings() screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height)) pygame.display.set_caption('Alien Invasion') # create a gamestats instance stats = GameStats(settings) # create game background galaxy = Galaxy(screen) # create a ship ship = Ship(settings, screen) # create bullets group bullets = Group() # create aliens group aliens = Group() # create the play button play_button = Button(settings, screen, 'Play') # create a score board scoreboard = Scoreboard(settings, screen, stats) # create sound buffer sound = Sound() # begin game main while while True: check_events(settings, screen, stats, ship, bullets, aliens, play_button, scoreboard, sound) if stats.game_active: ship.update_location() update_bullets(settings, screen, stats, ship, bullets, aliens, scoreboard, sound) update_aliens(settings, screen, stats, ship, bullets, aliens, scoreboard, sound) update_screen(settings, screen, stats, galaxy, ship, bullets, aliens, play_button, scoreboard)
def load_galaxy(galpath, galname, star_class_perc): """Loads the galaxy loacated at galpath and returns a Galaxy object""" gal_dict = OrderedDict() for color in ('g', 'i', 'r', 'u', 'z'): p = os.path.join(galpath, color + '.fits') if os.path.exists(p): gal_dict.update({color: fits.open(p, ignore_missing_end = True)}) continue p2 = os.path.join(galpath, galname + '_' + color + '.fits') if os.path.exists(p2): gal_dict.update({color: fits.open(p2, ignore_missing_end = True)}) continue p3 = os.path.join(galpath, galname + '-' + color + '.fits') if os.path.exists(p3): gal_dict.update({color: fits.open(p3, ignore_missing_end = True)}) continue # if no images were found if not gal_dict: return galpath # find the stars in the galaxies star_dict = OrderedDict() for color in gal_dict.keys(): try: p = os.path.join(galpath, color + '.fits') if os.path.exists(p): star_dict.update({color: get_sextractor_points(p)}) continue p2 = os.path.join(galpath, galname + '_' + color + '.fits') if os.path.exists(p2): star_dict.update({color: get_sextractor_points(p2)}) continue p3 = os.path.join(galpath, galname + '-' + color + '.fits') if os.path.exists(p3): star_dict.update({color: get_sextractor_points(p3)}) continue except SextractorError: return galpath return Galaxy(gal_dict, star_dict, star_class_perc, galname)
def main(): # Initialize the db db_config = {} with open(os.path.dirname(os.path.realpath(__file__)) + "\\db-config.json") as db_config_file: db_config = json.load(db_config_file) db.init(db_config['db-name'], user=db_config['user'], password=db_config['password'], host=db_config['host'], port=db_config['port']) db.connect() tables = db.get_tables() if 'Weather' in tables: db.drop_tables(Weather) db.create_tables([Weather]) # Create the galaxy we are gonna store ferengi = Planet(distance=500, speed=-1) betasoide = Planet(distance=2000, speed=-3) vulcan = Planet(distance=1000, speed=5) star_trek_galaxy = Galaxy([ferengi, betasoide, vulcan]) weather = {} with db.atomic(): for day in range(3650): weather['day'] = day alignment = star_trek_galaxy.planets_are_aligned(day) if alignment is PlanetsPosition.ALIGNED_WITH_THE_SUN: weather['weather'] = 'draft' elif alignment is PlanetsPosition.ALIGNED_WITH_EACHOTHER: weather['weather'] = 'perfect' else: # if we are here, planets are forming a polygon (sunsPosition, per) = star_trek_galaxy.calculate_suns_position(day) if sunsPosition is PlanetsPosition.SUN_INSIDE_POLYGON: weather['weather'] = 'rain' else: weather['weather'] = 'sunny' Weather.create(**weather)
'color': (35, 217, 89), 'init_amount': random.randint(500, 600), 'instances': 0, 'total_amount': 0 } } # Plots systems on a scatter for visuals pygame.init() FPS = 24 GALAXY_SIZE = 800 clock = pygame.time.Clock() screen = pygame.display.set_mode([GALAXY_SIZE, GALAXY_SIZE]) galaxy = Galaxy(game_screen=screen, galaxy_size=GALAXY_SIZE, system_count=10, allocation=RES_ALLOCATION, resource_deviation=.1, resource_variation=5, price_modifier=10) running = True while running: screen.fill((255, 255, 255)) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False galaxy.step() pygame.display.flip() clock.tick(FPS) pygame.quit()
projection = perspective(45.0, width / float(height), 1.0, 1000.0) program['u_projection'] = projection def keyboard(key, x, y): if key == '\033': sys.exit() def timer(fps): galaxy.update(100000) # in years ! program['a_size'] = galaxy['size'] glut.glutTimerFunc(1000 / fps, timer, fps) glut.glutPostRedisplay() galaxy = Galaxy(35000) galaxy.reset(13000, 4000, 0.0004, 0.90, 0.90, 0.5, 200, 300) glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) glut.glutCreateWindow('Galaxy') glut.glutReshapeWindow(800, 800) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutTimerFunc(1000 / 60, timer, 60) program = gloo.Program(vertex, fragment, count=len(galaxy)) view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32)
def __init__(self): self._players = [] self._galaxy = Galaxy() self._time = 0
#Create a generation error log errorlog = [] errorlocation = [] #Check for presence of galactic data file. try: with open('galactic_data.pkl', 'rb') as input: galaxy = pickle.load(input) except: # Break down input arguments if options.testflag is True: filename = "Test.csv" seed = 0.1234567890 random.seed(seed) galaxy = Galaxy(1000) #Number of particles galaxy.reset(13000, 4000, 0.0004, 0.85, 0.90, 0.5, 200, 300) galaxy.update(100000) else: # random.seed('earth') filename = "Production Run.csv" seed = 0.1234567890 random.seed(seed) if seed: random.seed(seed) galaxy = Galaxy(35000) #Number of particles galaxy.reset(13000, 4000, 0.0004, 0.85, 0.90, 0.5, 200, 300) galaxy.update(100000) exo = 0 # Loop to produce all planets for stars
def execute_this_fn(worker, *args, **kwargs): progress_signal = kwargs['progress_callback'] galaxy = Galaxy(target='release', api_host=API_HOST, api_key=API_KEY) def galaxy_eval(mouse): global last_frame_data if mouse[0] < -100: mouse = (mouse[0] + WorldSize[0], mouse[1]) galaxy.eval_step(mouse) frame_data = galaxy.frame if frame_data: galaxy.frame = None last_frame_data = frame_data im = render_frame(frame_data, scale=WorldScale) progress_signal.emit(im) boot_sequence = [ (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (8, 4), (2, -8), (3, 6), (0, -14), (-4, 10), (9, -3), (-4, 10), (1, 4), ] for mouse in boot_sequence: galaxy_eval(mouse) while not worker.cancelled: if worker.set_state: state = worker.set_state worker.set_state = None if state: galaxy.state = state if worker.ocr: worker.ocr = None im = render_frame(last_frame_data, scale=1) for symbol, box in ocr_image(im): print(' ', repr(symbol), repr(box)) if worker.redraw: worker.redraw = None if last_frame_data: im = render_frame(last_frame_data, scale=WorldScale) progress_signal.emit(im) mouse = worker.mouse_click if not mouse: time.sleep(0.1) continue worker.mouse_click = None print('mouse', mouse) galaxy_eval(mouse)