Example #1
0
    def __init__(self, x, y, direction):
        self.x, self.y = (x, y)
        self.direction = direction
        if direction < 0: self.speed = -800
        else: self.speed = 800

        self.emitter = emitter.StaticEmitter(
          rate=300,
          template=Particle(
              position=(x, y, 0),
              velocity=(0, 0, 0),
              color=(1, 1, 0, 0.5),
              size=(8, 8, 0),
              # rotation?
              # up?
          ),
          velocity=Disc((0,0,0), (0,0,1), 200),
          time_to_live=self.duration,
        )
        self.fader = controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=.5,end_alpha=0)

        self.group = ParticleGroup(
            controllers=[
                self.emitter,
                controller.Gravity((0, -100, 0)),
                controller.Movement(),
                self.fader,
                controller.Lifetime(1),
            ],
            renderer=Render('zap-star.png'),
        )
        self.emitter.emit(1, self.group)
Example #2
0
    def test_Movement_controller_min_velocity(self):
        from lepton import controller
        group = self._make_group()

        # Movement w/min velocity
        movement = controller.Movement(min_velocity=2.0)
        movement(0, group)
        p = list(group)
        self.assertMag(p[0].velocity, 0)
        self.assertMag(p[1].velocity, 2.0)
        self.assertMag(p[2].velocity, math.sqrt(12))
Example #3
0
    def test_Movement_controller_max_velocity(self):
        from lepton import controller
        group = self._make_group()

        # Movement w/max velocity
        movement = controller.Movement(max_velocity=0.5)
        movement(0, group)
        p = list(group)
        self.assertMag(p[0].velocity, 0)
        self.assertMag(p[1].velocity, 0.5)
        self.assertMag(p[2].velocity, 0.5)
Example #4
0
    def test_Movement_controller_damping_vector(self):
        from lepton import controller
        group = self._make_group()

        # Movement w/damping vector
        movement = controller.Movement(damping=(1, 0.9, 1))
        movement(0.1, group)
        p = list(group)
        self.assertVector(p[0].velocity, (0, 0, 0))
        self.assertVector(p[1].velocity, (1.0, 0.9, 1.0))
        self.assertVector(p[2].velocity, (-2.0, -1.8, -2.0))
Example #5
0
    def test_Movement_controller_damping_scalar(self):
        from lepton import controller
        group = self._make_group()

        # Movement w/damping
        movement = controller.Movement(damping=0.9)
        movement(0.1, group)
        p = list(group)
        self.assertVector(p[0].velocity, (0, 0, 0))
        self.assertVector(p[1].velocity, (0.9, 0.9, 0.9))
        self.assertVector(p[2].velocity, (-1.8, -1.8, -1.8))
Example #6
0
    def test_Movement_controller_simple(self):
        from lepton import controller
        group = self._make_group()

        # Simple movement, no acceleration or damping
        movement = controller.Movement()
        movement(0.2, group)
        p = list(group)
        self.assertVector(p[0].position, (0, 0, 0))
        self.assertVector(p[1].position, (0.2, 0.2, 0.2))
        self.assertVector(p[2].position, (0.6, 0.6, 0.6))
Example #7
0
 def particle_splash(self, pos, vel):
     img = self.load_sprite('sprites/drip')
     img.anchor_x = img.width / 2
     img.anchor_y = img.height / 2
     e = StaticEmitter(position=domain.Disc((pos.x, SEA_LEVEL, 0),
                                            (0, 0, 1), 50),
                       velocity=domain.Disc((vel.x, vel.y, 0), (0, 0, 1),
                                            200),
                       size=[(64.0, 64.0, 0), (80.0, 80.0, 0),
                             (100.0, 100.0, 0)],
                       template=Particle(color=(1.0, 1.0, 1.0, 1.0), ),
                       rate=100,
                       time_to_live=0.3)
     self.splash_group = ParticleGroup(controllers=[
         controller.Movement(),
         controller.Gravity((0, -900, 0)),
         controller.Lifetime(max_age=2), e
     ],
                                       renderer=Renderer(img),
                                       system=self.particles)
Example #8
0
 def __init__(self, x, y, size):
     self.emitter = emitter.StaticEmitter(
         template = Particle(
             position=(x, y, 0),
             color=(1, 1, 1, .01),
             velocity=(0, 0, 0),
             size=(64, 64, 0),
         ),
         velocity=Disc((0,0,0), (0,0,1), 400),
     )
     self.group = ParticleGroup(
         controllers=[
             self.emitter,
             controller.Growth(50),
             controller.Movement(),
             controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=.7,end_alpha=0),
             controller.Lifetime(.7),
         ],
         renderer = Render('point64.png'),
     )
     self.emitter.emit(50, self.group)
Example #9
0
 def load(cls):
     super(Rocket, cls).load()
     img = loader.image('data/sprites/rocket-spark.png')
     cls.particle_texture = img
     w = img.width
     h = img.height
     img.anchor_x = w * 0.5
     img.anchor_y = h * 0.5
     cls.particle_controllers = [
         controller.Movement(),
         controller.Lifetime(max_age=2),
         controller.Growth(30.0),
         controller.ColorBlender([
             (0, (1.0, 0.9, 0.0, 1.0)),
             (1, (0.0, 0.0, 0.0, 0.2)),
             (3, (0.0, 0.0, 0.0, 0.0)),
         ]),
         controller.Bounce(domain=domain.Plane((0, SEA_LEVEL, 0),
                                               (0, 1, 0)),
                           bounce=0.02)
     ]
     cls.particle_renderer = Renderer(cls.particle_texture)
Example #10
0
 def __init__(self, rect, scale=1):
     x, y = rect.center
     self.emitter = emitter.StaticEmitter(
         rate = 20,
         template = Particle(
             position=(x, y, 0),
             color=(1, 1, 1, .5),
             velocity=(0, 0, 0),
             size=(8, 8, 0),
         ),
         velocity=Disc((0,0,0), (0,0,1), rect.width*.75*scale),
     )
     self.group = ParticleGroup(
         controllers=[
             self.emitter,
             controller.Movement(),
             controller.Clumper(50),
             controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=1,end_alpha=0),
             controller.Lifetime(1),
         ],
         renderer = Render(self.filename),
     )
     self.emitter.emit(1, self.group)
Example #11
0
 def __init__(self, x1, y1, x2, y2):
     self.emitter = emitter.StaticEmitter(
         rate = (x2-x1) // 5,
         template = Particle(
             position=(x1, y1, 0),
             color=(1, 1, 1, .5),
             velocity=(0, 0, 0),
             size=(32, 32, 0),
         ),
         position=Line((x1, y1, 0), (x2, y1, 0)),
         velocity=AABox((-100, -50, 0), (100, -200, 1)),
     )
     self.group = ParticleGroup(
         controllers=[
             self.emitter,
             controller.Movement(),
             controller.Growth(100),
             controller.Gravity((0, -50, 0)),
             controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=1,end_alpha=0),
             controller.Lifetime(2),
         ],
         renderer = Render('black-bubble.png'),
     )
     self.emitter.emit(1, self.group)
Example #12
0
from wasabisg.particles import ParticleSystemNode

# The global particle system
# Groups within here will be renderer
# Actors should define emitters; the world will spawn these
particles = ParticleSystemNode()


def load(name):
    return pyglet.resource.texture(name)


wake_particles = particles.create_group(
    controllers=[
        #        Drag(0.1, 0.0, (0, 0, 0)),
        controller.Movement(),
        controller.Lifetime(5),
        controller.Fader(start_alpha=0.0,
                         max_alpha=0.3,
                         end_alpha=0.0,
                         fade_in_end=0.2,
                         fade_out_start=0.3,
                         fade_out_end=5.0)
    ],
    texture=load('foam.png'))

smoke_particles = particles.create_group(controllers=[
    controller.Movement(),
    controller.Lifetime(8),
    controller.Fader(start_alpha=0.0,
                     max_alpha=0.2,