def make_puff(prev_emitter): """Return emitter that generates the subtle smoke cloud left after a firework shell explodes""" return arcade.Emitter( center_xy=prev_emitter.get_pos(), emit_controller=arcade.EmitBurst(4), particle_factory=lambda emitter: arcade.FadeParticle( filename_or_texture=PUFF_TEXTURE, change_xy=(_Vec2(arcade.rand_in_circle( (0.0, 0.0), 0.4)) + _Vec2(0.3, 0.0)).as_tuple(), lifetime=4.0))
def test_vec_mult_and_divide(): v1 = _Vec2(5.0, 4.0) v2 = _Vec2(0.5, -0.25) v3 = v1 * v2 assert v3.x == 2.5 assert v3.y == -1.0 v4 = v3 / v2 assert v4.x == v1.x assert v4.y == v1.y
def test_vec_add_and_subtract(): v1 = _Vec2(5.0, 4.0) v2 = _Vec2(-1.5, 3.0) v3 = v1 + v2 assert v3.x == 3.5 assert v3.y == 7.0 v3 = v1 - v2 assert v3.x == 6.5 assert v3.y == 1.0
def __init__(self): super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) arcade.set_background_color(arcade.color.BLACK) self.emitters = [] self.frametime_plotter = FrametimePlotter() self.launch_firework(0) arcade.schedule(self.launch_spinner, 4.0) stars = arcade.Emitter( center_xy=(0.0, 0.0), emit_controller=arcade.EmitMaintainCount(20), particle_factory=lambda emitter: AnimatedAlphaParticle( filename_or_texture=random.choice(STAR_TEXTURES), change_xy=(0.0, 0.0), start_alpha=0, duration1=random.uniform(2.0, 6.0), mid_alpha=128, duration2=random.uniform(2.0, 6.0), end_alpha=0, center_xy=arcade.rand_in_rect((0.0, 0.0), SCREEN_WIDTH, SCREEN_HEIGHT) ) ) self.emitters.append(stars) self.cloud = arcade.Emitter( center_xy=(50, 500), change_xy=(0.15, 0), emit_controller=arcade.EmitMaintainCount(60), particle_factory=lambda emitter: AnimatedAlphaParticle( filename_or_texture=random.choice(CLOUD_TEXTURES), change_xy=(_Vec2(arcade.rand_in_circle((0.0, 0.0), 0.04)) + _Vec2(0.1, 0)).as_tuple(), start_alpha=0, duration1=random.uniform(5.0, 10.0), mid_alpha=255, duration2=random.uniform(5.0, 10.0), end_alpha=0, center_xy=arcade.rand_in_circle((0.0, 0.0), 50) ) ) self.emitters.append(self.cloud)
def create_emitter(self): self.emitter = arcade.Emitter( center_xy=(500, 500), change_xy=(0.15, 0), emit_controller=arcade.EmitMaintainCount(60), particle_factory=lambda emitter: AnimatedAlphaParticle( filename_or_texture=random.choice(CLOUD_TEXTURES), change_xy=(_Vec2(arcade.rand_in_circle((0.0, 0.0), 0.04)) + _Vec2(0.1, 0)).as_tuple(), start_alpha=0, duration1=random.uniform(5.0, 10.0), mid_alpha=255, duration2=random.uniform(5.0, 10.0), end_alpha=0, center_xy=arcade.rand_in_circle((0.0, 0.0), 50) ) )
def _emit(self): """Emit one particle, its initial position and velocity are relative to the position and angle of the emitter""" p = self.particle_factory(self) p.center_x += self.center_x p.center_y += self.center_y # given the velocity, rotate it by emitter's current angle vel = _Vec2(p.change_x, p.change_y).rotated(self.angle) p.change_x = vel.x p.change_y = vel.y self._particles.append(p)
def test_vec(): # 2 floats v = _Vec2(3.3, 5.5) assert v.x == 3.3 assert v.y == 5.5 # one tuple v = _Vec2((1.1, 2.2)) assert v.x == 1.1 assert v.y == 2.2 # iterator access items = [item for item in v] assert items == [1.1, 2.2] # tuple access assert v.as_tuple() == (1.1, 2.2) # string representation assert repr(v) == "Vec2(1.1,2.2)" assert str(v) == "Vec2(1.1,2.2)"
def test_vec_rotated(): v1 = _Vec2(3.0, 0.0) rotated = v1.rotated(0.0) assert rotated.x == approx(3.0) assert rotated.y == approx(0.0) rotated = v1.rotated(90.0) assert rotated.x == approx(0.0) assert rotated.y == approx(3.0) rotated = v1.rotated(-90.0) assert rotated.x == approx(0.0) assert rotated.y == approx(-3.0) rotated = v1.rotated(45.0) assert rotated.x == approx(2.12132) assert rotated.y == approx(2.12132)
def test_vec_length(): assert _Vec2(5.0, 0.0).length() == approx(5.0) assert _Vec2(0.0, -5.0).length() == approx(5.0) assert _Vec2(3.5355339, 3.5355339).length() == approx(5.0) assert _Vec2(-3.5355339, -3.5355339).length() == approx(5.0)
def test_vec_dot(): v1 = _Vec2(5.0, 4.0) v2 = _Vec2(0.5, -0.25) assert v1.dot(v2) == 1.5