Beispiel #1
0
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)
Beispiel #2
0
    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)
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
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)
Beispiel #6
0
disc = domain.Disc((0, 0, -50), (0, 0, 1), 1.5, 1.5)
viewer_plane = domain.Plane((0, 0, 0), (0, 0, -1))

jet = StaticEmitter(rate=2000,
                    position=disc,
                    template=Particle(color=(1, 1, 0), ),
                    deviation=Particle(velocity=(0, 0, 15),
                                       up=(0, 0, math.pi),
                                       color=(0.1, 0.1, 0.1)))

default_system.add_global_controller(
    Movement(max_velocity=10),
    Collector(viewer_plane),
    Gravity((0, 0, 15)),
    Growth(0.17),
    Fader(fade_in_end=0, max_alpha=0.3, fade_out_start=0, fade_out_end=8.0),
)

texture = image.load(os.path.join(os.path.dirname(__file__),
                                  'Particle.bmp')).get_texture()
group = ParticleGroup(controllers=[jet],
                      renderer=BillboardRenderer(SpriteTexturizer(texture.id)))

default_system.run_ahead(5, 40)

pyglet.clock.schedule_interval(default_system.update, (1.0 / 30.0))
pyglet.clock.set_fps_limit(None)
time = 0


def ring(dt):
Beispiel #7
0
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)

fire_tex = image.load(os.path.join(os.path.dirname(__file__),
Beispiel #8
0
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
angle = math.pi * 0.7
speed = 1.0
Beispiel #9
0
    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),
            ))
Beispiel #10
0
win.on_resize = on_resize

glClearColor(1, 1, 1, 1)
glEnable(GL_BLEND)
glShadeModel(GL_SMOOTH)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glDisable(GL_DEPTH_TEST)

logo_files = glob.glob(
    os.path.join(os.path.dirname(__file__), 'logo_frames/logo*.png'))
images = [pyglet.image.load(f) for f in sorted(logo_files)]
texturizer = FlipBookTexturizer.from_images(images + images[-1::-1], 0.075)

group = ParticleGroup(
    controllers=[Fader(fade_out_start=50.0, fade_out_end=58.5)],
    renderer=BillboardRenderer(texturizer))
template = Particle(
    size=(1, 1, 0),
    color=(1, 1, 1, 1),
)
positions = set([((x - 25) * 1.4 + (y % 2.0) * 0.7, (y - 25) * 1.4,
                  (z - 25) * 1.4 + (y % 2.0) * 0.7) for x in range(50)
                 for y in range(50) for z in range(50)])
group.new(template)
for i in range(12000):
    group.new(template, position=positions.pop(), age=49.35)

win.set_visible(True)
pyglet.clock.schedule_interval(default_system.update, (1.0 / 40.0))
pyglet.clock.set_fps_limit(None)
Beispiel #11
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__),
                                              'flare1.png')).texture
        group_tex.append((group, texture))
    win.resize = resize
Beispiel #12
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),
)

# Trails for electrons
trail_emitter = PerParticleEmitter(
    electrons,
Beispiel #13
0
		velocity=(0,-10,20),
	),
	color=[(1,0,0), (0,1,0), (0,0,1), (1,1,0), (1,0.5,0), (0.5,0,1)],
	rotation=[(0,0,0.3), (0,0,-0.3)],
	position=AABox((-100, 70, -100), (100, 70, -300)),
	deviation=Particle(
		color=(0.1, 0.1, 0.1, 0),
		rotation=(0,0,0.1),
		velocity=(0,5,0),
	)
)

default_system.add_global_controller(
	Movement(),
	Collector(Plane((0, 0, 0), (0, 0, -1))),
	Fader(fade_in_end=15.0),
)

font = pyglet.font.load(size=72)
# Try to force all glyphs into a single texture
font.texture_width = font.texture_height = 1024
letter_textures = font.get_glyphs(string.ascii_lowercase)
texturizer = SpriteTexturizer(
	letter_textures[0].texture.id,
	coords=[tex.tex_coords for tex in letter_textures],
	aspect_adjust_width=True)

group = ParticleGroup(controllers=[emitter],
	renderer=BillboardRenderer(texturizer))

win.set_visible(True)
Beispiel #14
0
		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()

if __name__ == '__main__':
	pyglet.app.run()
Beispiel #15
0
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):
        glLoadIdentity()
Beispiel #16
0
        Movement(),
    ],
    renderer=PointRenderer(16, texturizer),
)

trail_emitter = PerParticleEmitter(
    dust,
    rate=30,
    template=Particle(color=(1, 1, 1), ),
)

trail = ParticleGroup(
    controllers=[
        trail_emitter,
        Lifetime(.5),
        Fader(max_alpha=0.09, fade_out_start=0, fade_out_end=0.5)
    ],
    renderer=PointRenderer(14, texturizer),
)

win.set_visible(True)
win.on_resize(win.width, win.height)
pyglet.clock.schedule_interval(default_system.update, (1.0 / 60.0))

time = 0


def move_vortex(dt):
    global time, vortex
    time += dt
    if time > 10: