def setup_graphics(self, resolution): self.camera = graphics.Camera(self.window) self.scene = graphics.Scene(self.window) graphics.Layer(self.scene, cocos.layer.ColorLayer(0, 0, 0, 1)) for i in range(8): graphics.Layer( self.scene, graphics.BackgroundCocosLayer(self.camera, 10.0 + 0.5 * i, "starfield{0}.png".format(i))) self.hud_width = 170 self.main_layer = graphics.Layer(self.scene) self.main_layer.cocos_layer.position = self.camera.offset() self.main_layer.size = (self.window.width - self.hud_width, self.window.height) self.hud_cocos_layer = graphics.BlankingCocosLayer() self.hud_cocos_layer.clear_colour = (0, 40, 40, 255) self.hud_cocos_layer.clear_rect = ((self.window.width - self.hud_width, 0), (self.window.width, 0), (self.window.width, self.window.height), (self.window.width - self.hud_width, self.window.height)) self.hud_layer = graphics.Layer(self.scene, cocos_layer=self.hud_cocos_layer) self.hud_layer.cocos_layer.position = 0, 0 self.gem_images = pyglet.image.ImageGrid( pyglet.image.load("gems3.png"), 4, 4) self.atlas = Atlas("atlas.generated") self.object_psys = bsgl.System( texture_id=self.atlas.sheet.get_texture().id) self.hud_psys = bsgl.System( texture_id=self.atlas.sheet.get_texture().id)
def run_game(): # game settings cells = Group() gameset = Settings() gamestat = GameStat() atlas = Atlas(gameset) pygame.init() screen = pygame.display.set_mode((gameset.scr_width, gameset.scr_height)) pygame.display.set_caption("Conway's Game of Life") # main loop. 2 steps only for test. evolvecount = 2 while True: gf.check_events(gameset, gamestat, screen, atlas, cells) # when the mouse is pressed down, begin setcell if gamestat.setcell: gf.check_setcell(gameset, gamestat, screen, atlas, cells) print('matrix after cellset') print(atlas.matrix) # when game is on, atlas evolve itself. if not gamestat.paused: atlas.evolve() evolvecount -= 1 # create cells according to atlas, and draw them. gf.create_cells(gameset, gamestat, screen, atlas, cells) gf.update_screen(gameset, screen, atlas, cells)
def __init__(self): pg.init() self.fps = 60 self.clock = pg.time.Clock() self.ship = Ship() self.screen = Screen(self.ship, self.clock) self.atlas = Atlas() self.fragments = Fragments(Vector(0, 0), self.atlas.dim, int(abs(self.atlas.dim) / 10)) self.all = [self.screen, self.fragments, self.ship, self.atlas]
def input_analysis(name: str, test: list): """ This function calulaces the input mean/variance from both the provided human input and the open pose input. :param str name: Is the name of the set in dataset diretory. :param list test: Test method if several is avaible. """ dataobj = dataset(name) atlasobj = Atlas(dataobj.setconf) dataobj.set_atlas(atlasobj) print(f"Created dataset object {name} {dataobj} size = {dataobj.count}") dataobj.create_views()
def test_set(name): """ Tests a set in the dataset directory. :param str name: is the name of the dataset that is loaded with this function """ # conf = None # with open('./readset.yaml','r') as f: # conf = yaml.load(f,Loader=yaml.FullLoader) print("test") datap1 = dataset(name) myatlas = Atlas(datap1.setconf) datap1.set_atlas(myatlas) print(f"Created dataset object {name} {datap1} size = {datap1.count}") datap1.create_views() print("Done. Loaded all images") datap1.show_atlas() print("builds the atlas") datap1.build_atlas() print('Sovle geometry') # datap1.geometry_solver() datap1.create_latex_img_table(4) print("end")
if len(sys.argv) not in [2, 3]: print("Usage: gps.py numCities|atlasFile [debugLevel].") sys.exit(1) if len(sys.argv) > 2: if sys.argv[2] not in ['DEBUG', 'INFO', 'WARNING', 'ERROR']: print('Debug level must be one of: DEBUG, INFO, WARNING, ERROR.') sys.exit(2) logging.getLogger().setLevel(sys.argv[2]) else: logging.getLogger().setLevel('INFO') try: num_cities = int(sys.argv[1]) logging.info( 'Building random atlas with {} cities...'.format(num_cities)) usa = Atlas(num_cities) logging.info('...built.') except: logging.info('Loading atlas from file {}...'.format(sys.argv[1])) usa = Atlas.from_filename(sys.argv[1]) logging.info('...loaded.') path, cost = find_best_path(usa) print('Best path from {} to {} costs {}: {}.'.format( 0, usa.get_num_cities() - 1, cost, path)) print('You expanded {} nodes: {}'.format(len(usa._nodes_expanded), usa._nodes_expanded))
# # Execute the ETL job in Spark ... # print("==> Executing Spark ETL job ") master = "local[*]" appName = "Simple ETL Job" sc = SparkContext(master, appName) sc.setLogLevel("ERROR") sqlContext = HiveContext(sc) startTime = datetime.utcnow() emp_dept_flat = etl() endTime = datetime.utcnow() print("Started: %s" % startTime.isoformat()) print("Ended: %s" % endTime.isoformat()) # # ... and add the lineage to Atlas # print("Adding Lineage to Atlas (using the code in function 'etl')") atlas = Atlas(cluster, atlasHost, user, password) atlas.lineage.createHiveToHive(sourceDB, sourceTables, targetDB, targetTable, targetColumns, \ etl, usedSparkPackages, atlas.timestamp(startTime), atlas.timestamp(endTime), owner) print("Done")
when = c.data.split('_')[3] keyboard = templates.HOURS_INLINE(when) bot.answer_callback_query(c.id) bot.edit_message_text("Set hour:", message.chat.id, message.message_id, reply_markup=keyboard) @bot.callback_query_handler(func=lambda c: c.data.startswith('min')) def change_minute(c: telebot.types.CallbackQuery): if not check_admin_rights(c): return message = c.message when = c.data.split('_')[1] m = c.data.split('_')[2] atlas.change_minute(message.chat.id, when, m) time = atlas.time(message.chat.id, when) bot.answer_callback_query(c.id, "Time is changed to " + time) if __name__ == '__main__': atlas = Atlas() templates = Templates(atlas) sender = Sender() sender.start() try: bot.polling(none_stop=True) except: pass
def __init__(self, window, continuation_with_ship=None, **kwargs): super(GarageWorld, self).__init__(**kwargs) self.window = window self.scene = graphics.Scene(self.window) self.sim = physics.PhysicsSimulator(timestep=None) self.input_layer = gameinput.CocosInputLayer() layer = graphics.Layer(self.scene, cocos.layer.ColorLayer(128, 0, 128, 255)) graphics.Layer(self.scene, cocos_layer=graphics.FunctionCocosLayer(self.draw_psys)) layer.cocos_layer.position = 0, 0 graphics.Layer(self.scene, self.input_layer) self.atlas = Atlas("atlas.generated") self.object_psys = bsgl.System( texture_id=self.atlas.sheet.get_texture().id) self.input_layer.mouse_motion_hooks.append(self.on_mouse_motion) self.main_layer = graphics.Layer(self.scene) self.root_node = cocos.cocosnode.CocosNode() self.main_layer.cocos_layer.add(self.root_node) self.continuation_with_ship = continuation_with_ship root = PolygonBlock.load_file("blocks/poly5.yaml") self.root_node.scale = 1 # for i in range(7): # a = s.attach((0,i), blocks.QuadBlock(32), 0) # b = s.attach((a,2), blocks.QuadBlock(32), 0) # c = s.attach((b,2), blocks.QuadBlock(32), 0) # d = s.attach((c,1), blocks.QuadBlock(32), 3) # self.sprite_structure = None self.garage_ship = None self.block_shapes = map( lambda n: (lambda: PolygonBlock.load_file("blocks/poly{}.yaml".format(n))), (3, 4, 5, 6, 8)) self.block_decorators = [ decorate_block_armour, decorate_block_battery, decorate_block_generator ] self.block_gun_mounter = decorate_block_with_guns_within self.block_engine_mounter = decorate_block_with_engines_within self.current_block_shape = self.block_shapes[0] self.current_block_decorator = self.block_decorators[0] self.restart_block_structure() self.mouse_index = None self.current_rotation = 0.0 self.current_position = (0, 0) self.set_current_block() self.input_layer.mouse_scroll_hooks.add_anonymous_hook( self.on_mouse_scroll) if self.continuation_with_ship: self.input_layer.set_key_press_hook(key.ENTER, self.on_continue_with_ship) self.input_layer.set_key_press_hook(key.SPACE, self.on_place_block) self.input_layer.set_key_press_hook(key.UP, self.on_next_shape) self.input_layer.set_key_press_hook(key.DOWN, self.on_previous_shape) self.input_layer.set_key_press_hook(key.RIGHT, self.on_next_decorator) self.input_layer.set_key_press_hook(key.LEFT, self.on_previous_decorator) self.input_layer.set_key_press_hook(key.R, self.on_restart_with_current) self.input_layer.set_key_press_hook(key.P, self.on_save_ship) self.input_layer.set_key_press_hook(key.L, self.on_load_ship) self.input_layer.mouse_press_hooks[mouse.RIGHT] = self.on_next_shape self.input_layer.mouse_press_hooks[mouse.LEFT] = self.on_place_block self.refresh_garage_ship() self.physics.add_anonymous_hook(self.sim.tick) self.idle_time = 0.0 self.currently_idle = False
def set_atlas(self, atlas_name, atlas_file_loc): self.atlas = Atlas(atlas_name, atlas_file_loc)
def main(): include_build_directory() import pyglet import pyglet.gl import bsgl import sys window = pyglet.window.Window(vsync=True, width=1300, height=1000) print window.width, window.height label = pyglet.text.Label("Hello world!", font_name="Times New Roman", font_size=36, x=window.width // 2, y=window.height // 2, anchor_x="center", anchor_y="center") atlas = Atlas("atlas.generated") tex = atlas.sheet.get_texture() fps = pyglet.clock.ClockDisplay() pyglet.clock.schedule(lambda _: None) t0 = [time.time(), time.time()] psys = bsgl.System(texture_id=tex.id) print psys.get_capacity(), psys.get_number_of_elements() amount = 1000 psys.reserve(amount) things = {} def add_things(): for i in range(amount): z = random.random() * 6.28 r = 0.001 + random.random() * 0.01 pos = r * math.cos(z), r * math.sin(z) vel = tuple( Vec2d(pos).normalized() * (1 + 4 * random.random()) * 3) offset = 0, 0 texcoords = 0, 0 texsize = 1, 1 angle = random.random() * 6.28 avel = (-1 if random.random() > 0.5 else 1) * ( random.random() * 0.1 + 0.9) * 10 * Vec2d(vel).get_length() size = (0.1, 0.1) rgba = [random.random() for i in range(3)] + [1.0] name = "polygon_normals.{}.generated".format( random.choice((3, 4, 5, 6, 8))) rv = psys.add(size=size, texture_coordinates=atlas.texcoords(name), texture_size=atlas.texsize(name), position=pos, offset=offset, angle=angle, colour=rgba) things[rv] = (pos, angle, vel, avel) def update_things(dt): for index, (pos, a, vel, avel) in things.items(): x, y = pos dx, dy = vel t = 0.2 * dt xp, yp = x + t * dx, y + t * dy ap = a + t * avel things[index] = ((xp, yp), ap, vel, avel) psys.update_position_and_angle(index, (xp, yp), ap) def reset_things(): for index in things.keys(): del things[index] psys.remove(index) assert len(things) == 0 add_things() add_things() indices = things.keys() add_things() for index in indices: psys.remove(index) del things[index] print psys.get_capacity(), psys.get_number_of_elements() @window.event def on_draw(): pyglet.gl.glClearColor(0.5, 0.2, 0.5, 1.0) window.clear() label.draw() t1 = time.time() dt = t1 - t0[0] t0[0] = t1 if (t1 - t0[1]) > 3.0: reset_things() t0[1] = t1 update_things(dt) psys.draw() # position = (dt,2*dt) ) fps.draw() pyglet.app.run()
def setup(name, height, width): # setup atlas atlas = Atlas(name, height, width) return atlas
import os import sys import logging SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) PACKAGE_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..")) sys.path.append(PACKAGE_PATH) from settings import * level = logging.INFO if os.getenv("LOGGING_DEBUG"): level = logging.DEBUG logging.basicConfig( level=level, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', ) from atlas import Atlas from apf.consumers import KafkaConsumer as Consumer consumer = Consumer(config=CONSUMER_CONFIG) step = Atlas(consumer, config=STEP_CONFIG, level=level) step.start()
def create_and_run(idx, Consumer): CONSUMER_CONFIG["ID"] = idx consumer = Consumer(config=CONSUMER_CONFIG) step = Atlas(consumer, config=STEP_CONFIG, level=level) step.start()
def init_atlas(debug=False): global atlas, username, password, api_url load_credentials() atlas = Atlas(username, password, api_url, verify_credentials=False, debug=debug)