def __init__(self, filename=None): super(AnimFont, self).__init__() self.frames = list() self.current = 0 self.__anim = Animation() if filename != None: self.load(filename)
def __init__(self, rect, speed, tileset, level, maxHealth, **kwargs): super().__init__(rect=rect, dirRule=lambda: { -1: Direction.Left, 0: None, 1: Direction.Right, }[self.move.getDir(x=True)], idName="enemy", baseHealth=maxHealth, **kwargs) self.collision = Collision(self, level, "enemy") self.move = Move(self, speed, self.collision) self.gravity = GravityLine(self, 2, h=level.map.h // 2) self._ai = AI(self) def _isMoving(): return self.move.getSpeed(x=True) != 0 def _hDir(): return self.move.getDir(x=True) def _vDir(): return {False: -1, True: 1}[self.gravity.positiveDir()] image = Files.loadImage(tileset) self._display = Display(image, self, Animation(image, 11, _isMoving, _hDir, _vDir), True)
def animate(debug_mode, render_function, duration, screen_size, fps, scene): # duration in seconds render_function = render if debug_mode else render_function animation = Animation(duration, screen_size, fps, scene, render_function) sphere = scene.objects[0] main_camera = scene.cameras[0] animation.create(sphere, main_camera)
def construct(self): scale_factor = 0.9 grid = Grid(4, 4, point_thickness=1) curve = HilbertCurve(order=2) for mob in grid, curve: mob.scale(scale_factor) words = TextMobject(""" Sequence of curves is stable $\\leftrightarrow$ existence of limit curve """, size="\\normal") words.scale(1.25) words.to_edge(UP) self.add(curve, grid) self.dither() for n in range(3, 7): if n == 5: self.play(ShimmerIn(words)) new_grid = Grid(2**n, 2**n, point_thickness=1) new_curve = HilbertCurve(order=n) for mob in new_grid, new_curve: mob.scale(scale_factor) self.play(ShowCreation(new_grid), Animation(curve)) self.remove(grid) grid = new_grid self.play(Transform(curve, new_curve)) self.dither()
def __init__(self, speed, starting_position, texture, window_rectangle, collision_manager): self.window_rectangle = window_rectangle self.starting_position = starting_position self.speed = speed self.collision_manager = collision_manager self.direction = 1 if speed > 0 else -1 # Plane fly_anim = Animation() fly_anim.texture = texture fly_anim.add_frame(sf.Rectangle((0, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((176, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73))) self.plane = AnimatedSprite(sf.seconds(0.2), False, True) self.plane.play(fly_anim) self.plane.size = sf.Vector2(self.plane.global_bounds.width / 2, self.plane.global_bounds.height / 2) self.plane.origin = self.plane.global_bounds.width / 2.0, self.plane.global_bounds.height / 2.0 self.plane.scale((self.direction * 0.5, 0.5)) self.plane.position = self.starting_position self.plane_speed = sf.Vector2(speed, 0) self.is_dead = False self.jump_time = None self.plane_jumped = False self.immortal = None self.bullets = set() SoundManager.play_player_appear_sound()
def importAnimation(filename="out"): file = open(filename, 'rb') repeat = int.from_bytes(file.read(1), byteorder='big', signed=False) animation = Animation([], repeat) frames_count = int.from_bytes(file.read(4), byteorder='big', signed=False) animation.frames = [Frame(100, {}) for i in range(frames_count)] for i in range(frames_count): frame_hold = int.from_bytes(file.read(2), byteorder='big', signed=False) animation.frames[i].hold = frame_hold frame_led_count = int.from_bytes(file.read(1), byteorder='big', signed=False) for j in range(frame_led_count): frame_led_index = int.from_bytes(file.read(1), byteorder='big', signed=False) frame_led_red = int.from_bytes(file.read(1), byteorder='big', signed=False) frame_led_green = int.from_bytes(file.read(1), byteorder='big', signed=False) frame_led_blue = int.from_bytes(file.read(1), byteorder='big', signed=False) animation.frames[i].leds[frame_led_index] = Color( frame_led_red, frame_led_green, frame_led_blue) return animation
def flash(self): dur = randint(60, 100) ani = Animation(shade_alpha=0, duration=dur, transition="linear", round_values=True) ani2 = Animation(shade_alpha=240, duration=dur, delay=dur, transition="linear", round_values=True) ani.start(self) ani2.start(self) self.animations.add(ani, ani2) self.flash_time = randint(150, 350) choice(self.thunder_sounds).play()
def play(): ( controller_parameters, visual, parameters, history, ) = process_game_parameters() controllers = Controllers( parameters, history, controller_parameters, ) result = Result(parameters, history, controllers) plotting = Plotting( visual, parameters, history, controllers, result, ) animation = Animation( visual, parameters, history, controllers, plotting, result, ) animation.run()
def setUp(self) -> None: # Prepare data for processing self.anim = Animation( np.array([[1, 3, 4], [1, 2, 3], [1, 2, 2], [1, 2, 1], [1, 2, 1]])) self.lib_anim1 = Animation(np.array([[1, 3, 4], [1, 2, 3]])) self.lib_anim2 = Animation(np.array([[1, 2, 4], [1, 2, 3]])) self.lib_anim3 = Animation(np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])) self.lib = AnimationLibrary( [self.lib_anim1, self.lib_anim2, self.lib_anim3]) # Pack the data into the AnimationRecognitionProcessorInputData structure self.data = AnimationRecognitionProcessorInputData(self.anim, self.lib)
def mountains(self): return { 'neutral': Animation(name='neutral', frames=[self.get_sprite("mountains")], durations=[1234]) }
def foothills(self): return { 'neutral': Animation(name='neutral', frames=[self.get_sprite("foothills")], durations=[1234]) }
def __init__(self, game, x, y): self.idle_image = game.spritesheet.get_image_alpha_at_col_row(0, 1) self.image = self.idle_image super().__init__(game, x, y, self.image) self.hit_rect = (TILE_SIZE / 4, TILE_SIZE / 2, TILE_SIZE / 2, TILE_SIZE / 2) self.spd = 6 self.last_movex = 0.0 self.last_movey = 0.0 self.old_x = 0.0 self.old_y = 0.0 self.animation_timer = 0.0 self.idling_animation = Animation( 0.50, PlayMode.LOOP, game.spritesheet.get_image_alpha_at_col_row(0, 1), game.spritesheet.get_image_alpha_at_col_row(1, 1)) self.walking_animation_up = Animation( 0.10, PlayMode.LOOP, game.spritesheet.get_image_alpha_at_col_row(2, 1), game.spritesheet.get_image_alpha_at_col_row(3, 1), game.spritesheet.get_image_alpha_at_col_row(4, 1)) self.walking_animation_down = Animation( 0.10, PlayMode.LOOP, game.spritesheet.get_image_alpha_at_col_row(5, 1), game.spritesheet.get_image_alpha_at_col_row(6, 1), game.spritesheet.get_image_alpha_at_col_row(7, 1)) self.walking_animation_left = Animation( 0.10, PlayMode.LOOP, pg.transform.flip( game.spritesheet.get_image_alpha_at_col_row(5, 2), True, False), pg.transform.flip( game.spritesheet.get_image_alpha_at_col_row(6, 2), True, False), pg.transform.flip( game.spritesheet.get_image_alpha_at_col_row(7, 2), True, False)) self.walking_animation_right = Animation( 0.10, PlayMode.LOOP, game.spritesheet.get_image_alpha_at_col_row(5, 2), game.spritesheet.get_image_alpha_at_col_row(6, 2), game.spritesheet.get_image_alpha_at_col_row(7, 2)) self.container = Container(self, 16)
def go_down(self): ani = Animation(y=80, duration=self.time_span // 2, round_values=True, transition="in_quad") ani.callback = self.finish ani.start(self.rect) self.animations.add(ani)
def fade_out(self): ani = Animation(curtain_alpha=255, duration=6000, round_values=True, transition="out_quad") ani.callback = self.leave_state ani.start(self) self.animations.add(ani)
def onDestroy(self): random.choice(self.death_sounds).play() self.all_sprites.add( Animation(self.screen, self.config.explosion_anim_dir, self.rect.centerx, self.rect.centery)) for frag in self.getRandomDebries(): self.all_sprites.add(frag) self.kill()
def advance_one(self, now=False): if now: self.platten.left -= self.char_width else: remove_animations_of(self.platten, self._animations) ani = Animation(left=-self.char_width, relative=True, duration=self.platten_speed) ani.start(self.platten) self._animations.add(ani)
def test_diff_animations(self): # Input animations a1 = Animation(np.array([[1, 2, 4], [1, 2, 3]])) a2 = Animation(np.array([[1, 3, 2], [0.5, 2, 3]])) a3 = Animation(np.array([[1, 3, 2], [0.5, 2, 3], [0.5, 2, 3]])) # # Test simple subtraction difference (sub) diff = np.array([[0, -1, 2], [0.5, 0, 0]]) self.assertTrue(np.array_equal(diff, a1.diff(a2, diff_type="sub"))) # # Test absolute difference (abs) diff_abs = np.array([[0, 1, 2], [0.5, 0, 0]]) self.assertTrue(np.array_equal(diff_abs, a1.diff(a2, diff_type="abs"))) # # Test square difference (square) diff_square = np.array([[0, 1, 4], [0.25, 0, 0]]) self.assertTrue(np.array_equal(diff_square, a1.diff(a2))) self.assertTrue( np.array_equal(diff_square, a1.diff(a2, diff_type="square"))) # # Test that diff() throws exception if diff_type argument is wrong with self.assertRaises(ValueError): self.assertTrue( np.array_equal(diff, a1.diff(a2, diff_type="wrong_arg"))) # # Test that args of other types raise error with self.assertRaises(TypeError): a1.diff([]) with self.assertRaises(TypeError): a1.diff(None) with self.assertRaises(TypeError): a1.diff(a2, diff_type=1) # Check that with the different matrix sizes we have ValueError with self.assertRaises(ValueError): self.assertTrue(np.array_equal(diff, a1.diff(a3)))
def test_constructor(self): # Test empty library a = AnimationLibrary() self.assertEqual(a.size(), 0) a = AnimationLibrary([]) self.assertEqual(a.size(), 0) # Test with a single argument a = AnimationLibrary([Animation()]) self.assertEqual(a.size(), 1) # Test with multiple arguments a = AnimationLibrary([Animation(), Animation()]) self.assertEqual(a.size(), 2) self.assertEqual(a.animations()[0], a.animations()[1]) # Test for value errors with self.assertRaises(ValueError): AnimationLibrary("wrong_type") with self.assertRaises(ValueError): AnimationLibrary(["wrong_type"]) with self.assertRaises(ValueError): AnimationLibrary([Animation(), "wrong_type"]) library_animation1 = Animation(np.array([[1, 3, 4], [1, 2, 3]])) library_animation2 = Animation(np.array([[2, 3, 4], [1, 2, 3]])) library_animation3 = Animation(np.array([[2, 3, 4], [1, 2, 2.5]])) AnimationLibrary( [library_animation1, library_animation2, library_animation3])
def __init__(self, quoteManager): self.quoteManager = quoteManager self.idleAnim = Animation(SpriteSheet(PLAYER_IDLE_PATH, 19, 26), 4, 0.5) self.walkAnim = Animation(SpriteSheet(PLAYER_WALK_PATH, 19, 26), 9, 0.25) self.runAnim = Animation(SpriteSheet(PLAYER_RUN_PATH, 19, 26), 5, 0.1) self.anims = [self.idleAnim, self.walkAnim, self.runAnim] self.currentAnim = 0 # Get the width and height from the SpriteSheet self.width = self.idleAnim.sheet.tw self.height = self.idleAnim.sheet.th self.prevPos = 0 self.pos = 0
def __init__(self) -> None: super().__init__() self.type = ItemType.EXIT_POINT self.animation = Animation(sprites=((0, 46 * 16), (1 * 16, 46 * 16), (2 * 16, 46 * 16), (3 * 16, 46 * 16)), width=16, height=16, speed=10)
def goto_destination(self, destination_vertex_id): x, y = self.visitor.graph.vertex_index[ destination_vertex_id].coordinates # x_anim = Animation(self.rect, centerx=x, duration=1000, transition="in_quad") # y_anim = Animation(self.rect, centery=y, duration=1000, transition="out_quad") x_anim = Animation(self.rect, centerx=x, duration=1000, transition="in_out_quint") y_anim = Animation(self.rect, centery=y, duration=1000, transition="in_out_quint") self.animations.add(x_anim) self.animations.add(y_anim) x_anim.schedule( partial(self.on_arrived_at_new_destination, destination_vertex_id), "on finish")
def save(self, filename): """Save the font to the given path.""" out = Animation() out.width = self.__anim.width out.height = self.__anim.height out.frames = [self.bitmap, Frame(out.width, out.height)] for i in range(96): out.frames[1].set_font_dot(i%self.__anim.width, i/self.__anim.width, self.char_widths[i]) out.save_old(filename)
def green_bullet(self): return { 'neutral': Animation('neutral', [ self.get_sprite('green_proj_1'), self.get_sprite('green_proj_2') ], [450, 90], Vector2(6, 6), [Vector2(1, 1), Vector2(1, 1)]) }
def assault_soldier_green(self): neutral = self.get_sprite("assault_soldier_neutral") return { 'face_right': Animation(name='face_right', frames=[neutral], durations=[1234], hitbox_size=Vector2(24, 50), offsets=[Vector2(-12, -9)]), 'face_left': Animation(name='face_left', frames=[transform.flip(neutral, True, False)], durations=[1234], hitbox_size=Vector2(24, 50), offsets=[Vector2(-27, -9)]), 'projectile': self.green_bullet() }
def __init__(self, x, y): super(Enemy, self).__init__() if random.randint(0, 1) == 1: self.anim = Animation(ENEMY_2_WALK, x, y, (SIZE[0] + 25, SIZE[1]), True, False) else: self.anim = Animation(ENEMY_1_WALK, x, y, (SIZE[0] + 25, SIZE[1]), True, False) self.image = self.anim.image self.rect = self.anim.rect self.hp = 10 + random.randint(-7, 10) self.vel_x = 4 self.path = level1 self.vel_y = 4 self.reward = 2 + random.randint(-1, 3) self.dmg = 3 + random.randint(1, 3) self.hp_fix = self.hp self.radius = SIZE[0] // 3
def test_fix_large_phi(): # Model parameters L1 = 2.2 L2 = 1.2 L3 = 2 V = -2 # Simulation parameters dt = 0.05 steps = 1000 # Set the figure and axis for the animation fig, axis = plt.subplots(1) plt.gca().set_aspect('equal', adjustable='box') axis.set_xlim(0, 30) axis.set_ylim(0, 30) my_car = Car(L1, L2, axis, fig) my_trailer = Trailer(L3, axis, fig) # Define initial state of the system state = {} state["theta1"] = 0 state["phi"] = np.pi - 0.1 state["theta2"] = state["theta1"] + state["phi"] state["current_position"] = np.array((15, 15)) state["delta"] = 0.2 # Initiate list to save all state points points = [] points.append((state["current_position"], state["theta1"], state["theta2"], state["delta"])) # Start simulation for i in xrange(steps): # In case of a large phi angle, fix it #if np.abs(state["phi"] - np.pi) > CONTROLLER_MAX_ANGLE: # fix_large_phi(my_car, my_trailer, points, state, dt, V) # Restrain again delta value, only for testing purposes state["delta"] = move_wheels(state["delta"], 0.2) # Run simulation step simulation_step(my_car, my_trailer, state, V, dt) # Add new state point add_state_to_point(state, points) # Display simulation print(len(points)) animation = Animation(my_car, my_trailer, points) simulation = FuncAnimation(fig, animation.update, interval=100, frames=len(points), repeat=True, blit=True) animation.show()
def wall_animation(self, width, height): return { 'neutral': Animation( 'neutral', [transform.scale(self.get_sprite("black"), (width, height))], [1000], Vector2(width, height)) }
def __init__(self, settings, screen, images): """Initialize the blob""" super().__init__(settings, screen, images) # Override the start position self.dx = self.settings.enemy_blob_dx # Set the blob-specific animations self.animations[self.settings.anim_name_walk_left] = Animation( [0, 1, 2, 1], 2) self.animations[self.settings.anim_name_walk_right] = Animation( [3, 4, 5, 4], 2) self.animations[self.settings.anim_name_jump_down_left] = Animation( [6], 1) self.animations[self.settings.anim_name_jump_down_right] = Animation( [6], 1) self.current_animation = self.settings.anim_name_walk_right self.facing_left = False
def __init__(self, position=(0, 0)): super(Player, self).__init__() self.animation = { "right": Animation((pygame.transform.rotate(sprite, -90) for sprite in settings.SPRITES["pacman"]), 0.17), "left": Animation((pygame.transform.rotate(sprite, 90) for sprite in settings.SPRITES["pacman"]), 0.17), "up": Animation((pygame.transform.rotate(sprite, 180) for sprite in settings.SPRITES["pacman"]), 0.17), "down": Animation((pygame.transform.rotate(sprite, 0) for sprite in settings.SPRITES["pacman"]), 0.17), "death": OneTimeAnimation(settings.SPRITES["death"], 0.17) } self.image = self.animation["right"].sprites[0] self.rect = self.image.get_rect(center=position) self.position = Vector2D(*position) self.tile_index = settings.get_tile_index(position) self.moving = False self.target = self.position self.direction = Vector2D(0, 0) self.radius = self.rect.width // 3 self.energized = True self.dead = False
def defineAnimations(self): anim = Animation("left") anim.speed = 20 anim.addFrame(self.spritesheet.getImage(4, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(0, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(0, 1, 32, 32)) self.animate.add(anim) anim = Animation("right") anim.speed = 20 anim.addFrame(self.spritesheet.getImage(4, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(1, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(1, 1, 32, 32)) self.animate.add(anim) anim = Animation("down") anim.speed = 20 anim.addFrame(self.spritesheet.getImage(4, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(2, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(2, 1, 32, 32)) self.animate.add(anim) anim = Animation("up") anim.speed = 20 anim.addFrame(self.spritesheet.getImage(4, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(3, 0, 32, 32)) anim.addFrame(self.spritesheet.getImage(3, 1, 32, 32)) self.animate.add(anim) anim = Animation("death") anim.speed = 10 anim.addFrame(self.spritesheet.getImage(0, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(1, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(2, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(3, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(4, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(5, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(6, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(7, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(8, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(9, 7, 32, 32)) anim.addFrame(self.spritesheet.getImage(10, 7, 32, 32)) self.animate.add(anim)