def displaySingleFrame(self): newPixels = [Pixel() for n in range(self.nLeds)] if self.timeToNextParticle == 0: if len(self.particles) < self.maxParticles: newParticle = particle.randomParticle(self.colors, self.nLeds, self.pParams) self.particles.append(newParticle) self.timeToNextParticle = randInt(0, self.timeToNextParticleMax) else: self.timeToNextParticle -= 1 deadParticles = [] for p in self.particles: p.display(newPixels) p.age() if p.isDed(): deadParticles.append(p) self.pixels[:] = [p.toTuple() for p in newPixels] self.pixels.show() for p in deadParticles: self.particles.remove(p)
def randomParticle(colors, nLeds, parameters): """ factory to create a random Particle """ center = randInt(0, nLeds) spread = randInt(*parameters["spread"].value) # drift = (randFloat(0, 1)-0.5)/100 drift = 0 ttl = randInt(*parameters["ttl"].value) gamma = randFloat(*parameters["gamma"].value) colorIndex = randInt(0, len(colors)) color = colors[colorIndex] return particle(center, spread, drift, ttl, color, gamma)
def displaySingleFrame(self): newPixels = [Pixel() for n in range(self.nLeds)] if self.timeToNextParticle == 0: if len(self.particles) < self.parameters["maxParticles"].value: newParticle = particle.randomParticle( palette.current, self.nLeds, self.parameters ) self.particles.append(newParticle) self.timeToNextParticle = randInt( 0, self.parameters["maxTimeToNextParticle"].value ) else: self.timeToNextParticle -= 1 deadParticles = [] for p in self.particles: p.display(newPixels) p.age() if p.isDed(): deadParticles.append(p) self.pixels[:] = [p.toTuple() for p in newPixels] self.pixels.show() for p in deadParticles: self.particles.remove(p)
def randomParticle(colors, nLeds, params: particleParams): """ factory to create a random Particle """ center = randInt(0, nLeds) spread = params.spread() #drift = (randFloat(0, 1)-0.5)/100 drift = 0 timeToLive = params.timeToLive() gamma = params.gamma() colorIndex = randInt(0, len(colors)) color = colors[colorIndex] return particle(center, spread, drift, timeToLive, color, gamma)
def initialize(self, maxParticles=18, initialParticles=4): self.timeToNextParticle = randInt( 0, self.parameters["maxTimeToNextParticle"].value ) self.particles = [ particle.randomParticle(palette.current, self.nLeds, self.parameters) for i in range(initialParticles) ]
def __init__(self, pixels, nLeds, colors=defaultColors, maxParticles=18, initialParticles=4): self.pixels = pixels self.nLeds = nLeds self.colors = colors self.maxParticles = maxParticles self.timeToNextParticleMax = 80 self.timeToNextParticle = randInt(0, self.timeToNextParticleMax) self.pParams = particleParams() self.particles = [ particle.randomParticle(self.colors, self.nLeds, self.pParams) for i in range(initialParticles) ]
def timeToLive(self): return randInt(self.ttlMin, self.ttlMax)
def spread(self): return randInt(self.spreadMin, self.spreadMax)