We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I am using python-mode to follow Particle System on NOC, the iterator issue couldn't be solved by my own. Apparently, in the particle system object, every operation were made on single object Particle. I've attached my code, please help.
def setup(): global ps size(800,300) randomSeed(1) ps = ParticleSystem(PVector(width/2,height/3)) background(255) smooth() frameRate(60) def draw(): global ps background(255) ps.addParticle() ps.run()
def __init__(self,location): self.location = location self.vel = PVector(random(-1,1),random(-1,1)) self.acc = PVector (0,0.05) self.lifespan = 255 def run(self): self.update() self.display() def update(self): self.location.add(self.vel) self.vel.add(self.acc) self.lifespan -= 2.0 def display(self): stroke(0,self.lifespan) strokeWeight(2) fill(255,255,0,self.lifespan) ellipse(self.location.x,self.location.y,12,12) def isDead(self): if (self.lifespan<=0.0): return True else: return False from Particle import * class ParticleSystem(object): def __init__(self,origin): self.origin=origin self.particles = [Particle(self.origin) for i in range(10)] ###****where i think the problem is **** def run(self): for particle in self.particles: particle.run() ###****where i think the problem is, every opreation is made on single object**** if particle.isDead() == True: self.particles.remove(particle) # for i in range(len(self.particles)): # print i,"---",self.particles[i].location def addParticle(self): p = Particle(self.origin) self.particles.append(p)