class Kaboom: lifetime = 0.6 color = (0.9, 0.6, 0.2, 0.3) spark_tex = pyglet.resource.texture('bullet.png') spark_texturizer = SpriteTexturizer(spark_tex.id) sparks = ParticleGroup(controllers=[ Lifetime(lifetime), Movement(damping=0.93), ColorBlender([(0, (1, 1, 1, 1)), (lifetime * 0.8, color), (lifetime, color)]), Fader(fade_out_start=0.3, fade_out_end=lifetime), ], renderer=BillboardRenderer(spark_texturizer)) trails = ParticleGroup(controllers=[ Lifetime(lifetime * 1.5), Movement(damping=0.83), ColorBlender([(0, (1, 1, 1, 1)), (1, color), (lifetime, color)]), Fader(max_alpha=0.75, fade_out_start=0, fade_out_end=lifetime), ], renderer=BillboardRenderer(spark_texturizer)) splosions = set() def __init__(self, position): x, y = position spark_emitter = StaticEmitter( template=Particle(position=(uniform(x - 5, x + 5), uniform(y - 5, y + 5), 0), size=(10, ) * 3, color=self.color), deviation=Particle(velocity=(gauss(0, 5), gauss(0, 5), 0), age=1.5), velocity=domain.Sphere((0, gauss(40, 20), 0), 60, 60)) spark_emitter.emit(int(gauss(60, 40)) + 50, self.sparks) spread = abs(gauss(0.4, 1.0)) self.trail_emitter = PerParticleEmitter( self.sparks, rate=uniform(5, 30), template=Particle(size=(6, ) * 3, color=self.color), deviation=Particle(velocity=(spread, spread, spread), age=self.lifetime * 0.75)) self.trails.bind_controller(self.trail_emitter) self.splosions.add(self) pyglet.clock.schedule_once(self.die, self.lifetime) def die(self, dt=None): self.trails.unbind_controller(self.trail_emitter) self.splosions.remove(self)
def __init__(self): color = (uniform(0, 1), uniform(0, 1), uniform(0, 1), 1) while max(color[:3]) < 0.9: color = (uniform(0, 1), uniform(0, 1), uniform(0, 1), 1) spark_emitter = StaticEmitter( template=Particle(position=(uniform(-50, 50), uniform(-30, 30), uniform(-30, 30)), color=color), deviation=Particle(velocity=(gauss(0, 5), gauss(0, 5), gauss(0, 5)), age=1.5), velocity=domain.Sphere((0, gauss(40, 20), 0), 60, 60)) self.sparks = ParticleGroup(controllers=[ Lifetime(self.lifetime * 0.75), Movement(damping=0.93), ColorBlender([(0, (1, 1, 1, 1)), (2, color), (self.lifetime, color)]), Fader(fade_out_start=1.0, fade_out_end=self.lifetime * 0.5), ], renderer=PointRenderer( abs(gauss(10, 3)), spark_texturizer)) spark_emitter.emit(int(gauss(60, 40)) + 50, self.sparks) spread = abs(gauss(0.4, 1.0)) self.trail_emitter = PerParticleEmitter( self.sparks, rate=uniform(5, 30), template=Particle(color=color), deviation=Particle(velocity=(spread, spread, spread), age=self.lifetime * 0.75)) self.trails = ParticleGroup(controllers=[ Lifetime(self.lifetime * 1.5), Movement(damping=0.83), ColorBlender([(0, (1, 1, 1, 1)), (1, color), (self.lifetime, color)]), Fader(max_alpha=0.75, fade_out_start=0, fade_out_end=gauss(self.lifetime, self.lifetime * 0.3)), self.trail_emitter ], renderer=PointRenderer( 10, trail_texturizer)) pyglet.clock.schedule_once(self.die, self.lifetime * 2)
class Debris: lifetime = 0.5 color = (1.0, 1.0, 1.0, 1.0) fragment_tex = pyglet.resource.texture('fragment.png') fragment_texturizer = SpriteTexturizer(fragment_tex.id) fragments = ParticleGroup(controllers=[ Lifetime(lifetime), Movement(), ], renderer=BillboardRenderer(fragment_texturizer), system=diffuse_system) @classmethod def emit(cls, position): emitter = StaticEmitter(template=Particle(position=(*position, 0), size=(16, ) * 3, rotation=(0, 0, 1), color=cls.color), deviation=Particle(age=0.2, rotation=(0, 0, 2)), velocity=domain.Disc((0, 0, 0), (0, 0, 1), 100)) emitter.emit(20, cls.fragments)
class Impact: lifetime = 0.5 color = (0.9, 0.6, 0.2, 0.3) spark_tex = pyglet.resource.texture('bullet.png') spark_texturizer = SpriteTexturizer(spark_tex.id) sparks = ParticleGroup(controllers=[ Lifetime(lifetime), Movement(), ColorBlender([(0, (1, 1, 1, 1)), (lifetime * 0.8, color), (lifetime, (0, 0, 0, 0))]), ], renderer=BillboardRenderer(spark_texturizer)) @classmethod def emit(cls, position, velocity): x, y = position + velocity * 0.3 emitter = StaticEmitter(template=Particle(position=(x, y, 0), size=(5, ) * 3, color=cls.color), deviation=Particle(age=0.2), velocity=domain.Disc((*-2 * velocity, 0), (0, 0, 1), 100)) emitter.emit(10, cls.sparks)
def explosion(self, pos, magnitude): sparks = ParticleGroup( controllers=[ Lifetime(3), Movement(damping=0.93), Fader(fade_out_start=0.75, fade_out_end=3.0), ], renderer=BillboardRenderer(SpriteTexturizer(self.particle1_tex.id))) spark_emitter = StaticEmitter( template=Particle( position=(pos[0], pos[1], 0), color=(1, 1, 1)), deviation=Particle( position=(1, 1, 0), velocity=(300, 300, 0), age=1.5), size=[(3, 3, 0), (4, 4, 0), (5, 5, 0), (5, 5, 0), (6, 6, 0), (7, 7, 0)]) spark_emitter.emit(magnitude, sparks) fire = ParticleGroup( controllers=[ Lifetime(2), Movement(damping=0.95), Growth(60), Fader(fade_in_start=0, start_alpha=0, fade_in_end=0.5, max_alpha=0.6, fade_out_start=1.0, fade_out_end=2.0) ], renderer=BillboardRenderer(SpriteTexturizer(self.smoke1_tex.id))) fire_emitter = StaticEmitter( template=Particle( position=(pos[0], pos[1], 0), size=(50, 50, 0)), deviation=Particle( position=(0.5, 0.5, 0), velocity=(70, 70, 0), size=(20, 20, 0), up=(0, 0, math.pi * 2), rotation=(0, 0, math.pi * 0.06), age=2, ), color=[(0.5, 0, 0), (0.5, 0.5, 0.5), (0.4, 0.1, 0.1), (0.85, 0.3, 0)], ) fire_emitter.emit(400, fire)
class Trail: LIFETIME = 0.2 sprite = pyglet.resource.texture('trail.png') group = ParticleGroup( controllers=[ Lifetime(LIFETIME), #Fader(start_alpha=1.0, fade_out_start=0, fade_out_end=LIFETIME), Growth(-50), Movement(), ], renderer=BillboardRenderer(SpriteTexturizer(sprite.id))) def __init__(self, player, viewport, level): self.player = player self.viewport = viewport self.level = level self.emitter = StaticEmitter( rate=player.body.velocity.length, template=Particle( position=(*level.map_to_world(player.position), 0), color=(1.0, 1.0, 1.0, 1.0), size=(16.0, ) * 3, ), ) self.group.bind_controller(self.emitter) pyglet.clock.schedule(self.update) def destroy(self): self.group.unbind_controller(self.emitter) def update(self, *_): level = self.level dir = self.player.body.velocity l = dir.length self.emitter.rate = l * 2 if self.player.health > 0 else 0 if l: back = self.player.position - dir.normalized() * 0.1 backwards = -0.1 * dir self.emitter.template.position = (*level.map_to_world(back), 0) self.emitter.template.velocity = (*level.map_to_world(backwards), 0) self.emitter.template.up = (0, 0, dir.get_angle() - self.viewport.angle)
def emit_sparks(self, pos, count): sparks = ParticleGroup( controllers=[ Lifetime(1), Movement(damping=0.93), Fader(fade_out_start=0.75, fade_out_end=1.0), ], renderer=BillboardRenderer(SpriteTexturizer(self.particle1_tex.id))) spark_emitter = StaticEmitter( template=Particle( position=(pos[0], pos[1], 0), color=(1, 1, 1)), deviation=Particle( position=(1, 1, 0), velocity=(100, 100, 0), age=1.5), size=[(6, 6, 0), (7, 7, 0), (12, 12, 0)]) spark_emitter.emit(count, sparks)
class Smoke: LIFETIME = 0.8 sprite = pyglet.resource.texture('smoke.png') group = ParticleGroup(controllers=[ Lifetime(LIFETIME), Fader(start_alpha=0.3, fade_out_start=0, fade_out_end=LIFETIME), Growth(100), Movement(), ], renderer=BillboardRenderer( SpriteTexturizer(sprite.id)), system=diffuse_system) def __init__(self, wpos): self.last_pos = wpos self.domain = Cylinder((*wpos, -10), (*wpos, 0), 5) self.emitter = StaticEmitter(rate=600, position=self.domain, template=Particle( color=(1.0, 1.0, 1.0, 0.3), size=(2.0, ) * 3, rotation=(0, 0, 1), velocity=(0, 0, 0), ), deviation=Particle( rotation=(0, 0, 0.5), angle=(0, 0, 6), )) self.group.bind_controller(self.emitter) def destroy(self): self.group.unbind_controller(self.emitter) def set_world_position(self, wpos, velocity): pos = Vec2d(wpos) back = pos - velocity self.domain.end_point1 = (*back, 0) self.domain.end_point0 = (*pos, 0) self.emitter.template.velocity = (*(-2 * velocity), 0)
from lepton.controller import Gravity, Lifetime, Movement, Fader, ColorBlender, Growth win = pyglet.window.Window(resizable=True, visible=False) win.clear() glEnable(GL_BLEND) glShadeModel(GL_SMOOTH) glBlendFunc(GL_SRC_ALPHA, GL_ONE) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glDisable(GL_DEPTH_TEST) spark_tex = image.load(os.path.join(os.path.dirname(__file__), 'flare3.png')).get_texture() sparks = ParticleGroup(controllers=[ Lifetime(3), Movement(damping=0.93), Fader(fade_out_start=0.75, fade_out_end=3.0), ], renderer=BillboardRenderer( SpriteTexturizer(spark_tex.id))) spark_emitter = StaticEmitter(template=Particle(position=(win.width / 2, win.height / 2, 0), color=(1, 1, 1)), deviation=Particle(position=(1, 1, 0), velocity=(300, 300, 0), age=1.5), size=[(3, 3, 0), (4, 4, 0), (5, 5, 0), (5, 5, 0), (6, 6, 0), (7, 7, 0)]) spark_emitter.emit(400, sparks)
0)), deviation=Particle(velocity=(5, 15, 0), size=(5, 5, 0)), position=[((width * i / 4), height, 0) for i in range(5)]) bubble = pygame.image.load( os.path.join(os.path.dirname(__file__), 'bubble.png')) water = ParticleGroup(controllers=[bubbler], renderer=BlitRenderer(display, bubble, rotate_and_scale=True)) default_system.add_global_controller( Lifetime(7), Gravity((0, -30, 0)), Movement(), Growth(4.5), #Fader(fade_in_end=5.0, max_alpha=0.005, fade_out_start=17, fade_out_end=20), ) while 1: for event in pygame.event.get(): if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): raise SystemExit ms = clock.tick() default_system.update(ms / 1000.0) display.fill((0, 0, 0)) default_system.draw()
] groups = [ ParticleGroup(controllers=[ StaticEmitter(rate=15000, position=domain, template=Particle( color=(1, 1, 1), size=(.1, .1, 0), )) ], renderer=renderer) for domain in domains ] default_system.add_global_controller( Lifetime(0.5), Fader(max_alpha=0.7, fade_out_start=0.1, fade_out_end=0.5), ) pyglet.clock.schedule_interval(default_system.update, (1.0 / 40.0)) pyglet.clock.set_fps_limit(None) translations = [(-1.1, -1.1), (1.1, -1.1), (-1.1, 1.1), (1.1, 1.1)] rot = 0 @win.event def on_draw(): global rot win.clear() for (xt, yt), group in zip(translations, groups):
glBlendFunc(GL_SRC_ALPHA, GL_ONE) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glDisable(GL_DEPTH_TEST) comet = StaticEmitter(rate=600, template=Particle( size=(2, 2, 0), color=(1, 1, 0), ), deviation=Particle(velocity=(0.7, 0.7, 0.7), up=(0, 0, math.pi), rotation=(0, 0, math.pi), color=(0.5, 0.5, 0.5))) default_system.add_global_controller( Lifetime(3.0), Movement(min_velocity=5), Fader(max_alpha=0.7, fade_out_start=1, fade_out_end=3.0), ) images = [ image.load(os.path.join(os.path.dirname(__file__), 'flare%s.png' % (i + 1))) for i in range(4) ] group = ParticleGroup(controllers=[comet], renderer=BillboardRenderer( SpriteTexturizer.from_images(images))) pyglet.clock.schedule_interval(default_system.update, (1.0 / 30.0)) pyglet.clock.set_fps_limit(None) arc_radius = 150
def __init__(self, x, y, z, r, side=-1, hp=50, controlable=False, weapon_range=5, dispersion=5, agility=50, weapon_base_damage=2, guidance=100, shortguide=0, partColor=(0.6, 0.5, 0.2, 1), firerate=10, shots=1, vo=30, maxvel=10, ammoMaxvel=20, combatDistance=50, behavior=0, commander=None, multipleTargets=False, name="", ammoDamp=0.98): self.name = name self.domain = Sphere( (x, y, z), r ) # a.center -> vector del centro , a.outer_radius -> radio externo , a.inner_radius -> radio interno self.size = r self.controller = Collector(self.domain, callback=self.contact) self.magnet = Magnet(self.domain, charge=guidance, exponent=shortguide) self.commander = commander self.mission = self.domain.center self.target = None self.alive = True self.targetMode = ['standard', 1] self.behavior = behavior # 0:free 1: escort 2: slave self.hp = hp self.agility = agility self.maxvel = maxvel self.timer = {0: 0, 1: 2, 2: 0, 3: 0, 4: 0} # timers placeholder self.counter = {0: 0, 1: 0} # counters placeholder self.side = side self.combatDistance = combatDistance self.velocity = Vec3(0, 0, 0) self.multipleTargets = multipleTargets self.firerate = firerate self.weapon_base_damage = weapon_base_damage wbd = self.weapon_base_damage rr = r * 2 self.dispersion = dispersion self.vo = vo self.ammoDamp = ammoDamp self.ammoMaxvel = ammoMaxvel self.shots = shots self.weapon_range = weapon_range self.xx = self.yy = self.zz = 0 self.Objective = Sphere((0, 0, 0), 1) self.color = partColor # (0.4,0.5,0.4,0.5) #self.prevController = Collector(self.domain)#DUMMY CONTROLLER self.controlable = controlable self.impacto = ParticleGroup(renderer=BillboardRenderer(texturizer), controllers=[ Lifetime(1), Fader(fade_out_start=0, fade_out_end=1), ]) self.deathplosion = ParticleGroup( renderer=BillboardRenderer(texturizer), controllers=[ Lifetime(self.size / 5 + 1), Fader(fade_out_start=0, fade_out_end=self.size / 5 + 1), ]) self.selector_emitter = StaticEmitter(template=Particle( position=(0, 0, 0), color=self.color, )) self.impacto_emitter = StaticEmitter( template=Particle( position=(0, 0, 0), color=(0.9, 0.8, 0.8), ), position=self.domain, #size=[(5, 5, 5), (10, 10, 10), (15, 15, 15)], ) self.hull = ParticleGroup(renderer=BillboardRenderer(texturizer2), controllers=[ Lifetime(100000), Movement(max_velocity=self.maxvel, damping=0.98), Magnet(self.Objective, charge=self.agility, exponent=0), ]) emiter = StaticEmitter(position=self.domain, template=Particle( color=self.color, size=(rr, rr, rr), )) emiter.emit(1, self.hull) if trails: if maxvel / r >= 20: self.trail = ParticleGroup( renderer=BillboardRenderer(texturizer2), controllers=[ Lifetime(trailSize[0]), Fader(fade_in_start=0, fade_in_end=0.1, fade_out_start=0, fade_out_end=trailSize[0]), Growth(-1 * r), PerParticleEmitter(self.hull, rate=trailSize[1], template=Particle( color=self.color, size=(rr, rr, rr), )), ]) self.ammo = ParticleGroup(renderer=BillboardRenderer(texturizer), controllers=[ self.magnet, Movement(min_velocity=0, max_velocity=self.ammoMaxvel, damping=self.ammoDamp), Lifetime(self.weapon_range), Fader(fade_out_start=self.weapon_range - 1, fade_out_end=self.weapon_range), ]) self.weapon = PerParticleEmitter( self.hull, # rate=self.firerate, template=Particle( velocity=self.velocity, # fixed value position=(self.getPosition()), color=partColor, ), position=self.domain, size=[(wbd * 0.5, wbd * 0.5, wbd * 0.5), (wbd, wbd, wbd), (wbd * 1.5, wbd * 1.5, wbd * 1.5)], deviation=Particle( velocity=(self.dispersion, self.dispersion, self.dispersion * d3), rotation=(0, 0, math.pi / 6), #color=(0.05,0.05,0.05,0), ))
rate=150, template=Particle( size=(10, 10, 0), color=(1, 1, 0) ), deviation=Particle( position=(0.1, 0.1, 0), velocity=(10, 10, 0.7), up=(0, 0, math.pi), rotation=(0, 0, math.pi), color=(0.5, 0.5, 0.5)) ) # Add group to ball ball.add_particle_group(comet) default_system.add_global_controller( Lifetime(1.75), # Gravity((0,-20,0)), Movement(min_velocity=20), Fader(max_alpha=0.7, fade_out_start=1, fade_out_end=1.75), ) group_tex = [] for i in range(4): group = ParticleGroup( controllers=[comet], renderer=BillboardRenderer()) try: texture = image.load(os.path.join(os.path.dirname(__file__), 'flare1.png')).texture # 'flare%s.png' % (i+1))).get_mipmapped_texture() except NotImplementedError: # Problem with mips not being implemented everywhere (cygwin?) texture = image.load(os.path.join(os.path.dirname(__file__),
Movement(), ]) proton_emitter = StaticEmitter(template=Particle( size=(30, 30, 0), color=(0.5, 1.0, 0.2, 0.5), ), size=[(26, 26, 0), (30, 30, 0), (34, 34, 0)], deviation=Particle(rotation=(0, 0, math.pi / 6), )) proton_emitter.emit(3, protons) electrons = ParticleGroup(renderer=BillboardRenderer(texturizer), controllers=[ Movement(min_velocity=10), Lifetime(electron_lifetime * 1.5), Magnet(nucleus, charge=15000.0), Magnet(nucleus, charge=-15000.0, exponent=3), Fader(fade_in_end=1, fade_out_start=electron_lifetime * 1.4, fade_out_end=electron_lifetime * 1.5), ]) electron_emitter = StaticEmitter( template=Particle( position=(-20, 0, 0), size=(25, 25, 25), color=(0.1, 0.1, 1.0), ), velocity=Disc((0, 0, 0), (-1, 0, 0), 36, 36), )
smoke = StaticEmitter( rate=10, template=Particle( position=(300,25,0), velocity=(0,35,0), color=(0.8,0.8,0.8,0.005), ), deviation=Particle( position=(10,5,0), velocity=(3,6,0), color=(0.05,0.05,0.05,0.0), ) ) default_system.add_global_controller( Lifetime(20), Gravity((0, -2, 0)), Movement(), Fader(fade_in_end=1.5, max_alpha=0.05, fade_out_start=12, fade_out_end=20), ) group1 = ParticleGroup(controllers=[smoke], renderer=PointRenderer(64, SpriteTexturizer(create_point_texture(64, 1)))) win.set_visible(True) pyglet.clock.schedule_interval(default_system.update, (1.0/30.0)) @win.event def on_draw(): win.clear() glLoadIdentity() default_system.draw()
glDisable(GL_DEPTH_TEST) flame = StaticEmitter(rate=500, template=Particle( position=(300, 25, 0), velocity=(0, 0, 0), color=(1, 1, 1, 1), ), position=Line((win.width / 2 - 85, -15, 0), (win.width / 2 + 85, -15, 0)), deviation=Particle(position=(10, 0, 0), velocity=(7, 50, 0), age=0.75)) default_system.add_global_controller( Lifetime(6), Gravity((0, 20, 0)), Movement(), ColorBlender([ (0, (0, 0, 0.5, 0)), (0.5, (0, 0, 0.5, 0.2)), (0.75, (0, 0.5, 1, 0.6)), (1.5, (1, 1, 0, 0.2)), (2.7, (0.9, 0.2, 0, 0.4)), (3.2, (0.6, 0.1, 0.05, 0.2)), (4.0, (0.8, 0.8, 0.8, 0.1)), (6.0, (0.8, 0.8, 0.8, 0)), ]), ) group = ParticleGroup(controllers=[flame],
velocity=(0, 0, 0), mass=1.0, color=(1, 1, 1, 0.25), ), position=source, deviation=Particle(velocity=(20, 0, 20), color=(0.0, 1.0, 1.0), age=0.5)) vortex = Cone((0, -30, 0), (0, 28, 0), 16, 0) front = AABox((-100, -50, -50), (100, 25, 0)) back = AABox((-100, -50, 50), (100, 25, 0)) dust = ParticleGroup( controllers=[ dust_emitter, Lifetime(8), Gravity((0, -20, 0)), Drag(0.0, 0.10, fluid_velocity=(80, 0, 0), domain=front), Drag(0.0, 0.10, fluid_velocity=(-80, 0, 0), domain=back), Magnet(charge=500, domain=vortex, exponent=0.75, epsilon=0.5), Movement(), ], renderer=PointRenderer(16, texturizer), ) trail_emitter = PerParticleEmitter( dust, rate=30, template=Particle(color=(1, 1, 1), ), )