示例#1
0
class ParticleLayer(Layer):
    """
    A ParticleSystem as a Layer...
    """
    def __init__(self, width, height, duration=None):
        super(ParticleLayer, self).__init__()
        self.buffer = Frame(width, height)
        self.start_time = None
        self.duration = duration
        # FIRE
        def emitter_dx(x): return random.randint(-10,10)
        def emitter_dy(x): return random.randint(-3,3)
        def dither_dx(x): return random.randint(-10,0)
        def dither_dy(x): return (x - 0.35)
        
        self.ps = ParticleSystem(width/2, height/2, max_life=20, max_particles=400, particles_per_update=20, emitter_dx_fn=emitter_dx, emitter_dy_fn=emitter_dy, dither_dx_fn=dither_dx, dither_dy_fn=dither_dy)
    
    def next_frame(self):
        # Assign the new script item:
        self.start_time = time.time()

        self.buffer.clear()
        self.ps.update()
        self.ps.draw(self.buffer.pySurface)
        return self.buffer
        
    def reset(self):
        """Resets the animation back to the first frame."""
        self.buffer.clear()
        self.ps.reset()
class ParticleLayer(Layer):
    """
    A ParticleSystem as a Layer...
    """

    def __init__(self, width, height, duration=None):
        super(ParticleLayer, self).__init__()
        self.buffer = Frame(width, height)
        self.start_time = None
        self.duration = duration
        # FIRE
        def emitter_dx(x):
            return random.randint(-10, 10)

        def emitter_dy(x):
            return random.randint(-3, 3)

        def dither_dx(x):
            return random.randint(-10, 0)

        def dither_dy(x):
            return x - 0.35

        self.ps = ParticleSystem(
            width / 2,
            height / 2,
            max_life=20,
            max_particles=400,
            particles_per_update=20,
            emitter_dx_fn=emitter_dx,
            emitter_dy_fn=emitter_dy,
            dither_dx_fn=dither_dx,
            dither_dy_fn=dither_dy,
        )

    def next_frame(self):
        # Assign the new script item:
        self.start_time = time.time()

        self.buffer.clear()
        self.ps.update()
        self.ps.draw(self.buffer.pySurface)
        return self.buffer

    def reset(self):
        """Resets the animation back to the first frame."""
        self.buffer.clear()
        self.ps.reset()
class ParticleLayer(Layer):
    """
    A ParticleSystem as a Layer...
    """
    def __init__(self, width, height, emitters, duration=None, num_hold_frames=1):
        super(ParticleLayer, self).__init__()
        self.buffer = Frame(width, height)
        self.start_time = None
        self.duration = duration
        self.width = width
        self.height = height
        self.num_hold_frames = num_hold_frames
        self.stalls = self.num_hold_frames
        # FIRE
        # def emitter_dx(x): return random.randint(-10,10)
        # def emitter_dy(x): return random.randint(-3,3)
        # def dither_dx(x): return random.randint(-10,0)
        # def dither_dy(x): return (x - 0.35)
        
        # self.ps = ParticleEmitter(width/2, height/2, max_life=20, max_particles=200, particles_per_update=100, total_creations=400, particle_class=Particle)
        self.ps = ParticleSystem(emitters=emitters, destination_texture=self.buffer.pySurface)

    
    def next_frame(self):
        # Assign the new script item:
        if(self.start_time is None):
            self.start_time = time.time()
        elif(self.duration is not None and (self.start_time + self.duration > time.time())):
            return None
        self.stalls = self.stalls - 1
        if(self.stalls <= 0):
            self.stalls = self.num_hold_frames
        else:
            return self.buffer

        self.buffer.clear()
        self.ps.update()
        self.ps.draw()
        return self.buffer
        
    def reset(self):
        """Resets the animation back to the first frame."""
        self.start_time = None
        self.stalls = self.num_hold_frames
        self.buffer.clear()
        self.ps.reset()