class Particle(BaseItem): def __init__(self): lifetime = randint(300, 500) # 400, 600 vortex = Vortex.random_vortex() BaseItem.__init__(self, lifetime, vortex) c = [settings.get_uniform('particle-red-range'), \ settings.get_uniform('particle-green-range'), \ settings.get_uniform('particle-blue-range'), \ settings['particle-transparency']] self.color = c # set transform for z to be 1 above floor self.transforms = [[0.,0.,1.],[0.,0.,0.],1.] self.pos = [0.,0.,0.] RandPlay() def step(self): self.vortex.step() self.age += 1 def draw(self): self.buffer = PointCloud([self.vortex.pos],[self.color]) self.buffer.sprite('data/particle.bmp') self.buffer.pointSize(200.0) self.buffer.draw()
class Engine: def __init__(self): self.particles = [] def add_particle(self): self.particles.append(Particle.RandomParticle()) def step(self): for particle in self.particles: if particle.expired(): self.particles.remove(particle) continue particle.step() particle.age += 1 if random() < 0.1: for _ in range(randint(1, 5)): self.add_particle() def draw(self): if not len(self.particles): return self.buffer = PointCloud([x.vortex.pos for x in self.particles], [x.color for x in self.particles]) self.buffer.sprite('data/particle.bmp') self.buffer.pointSize(105.0) self.buffer.draw()
class Obj (BaseItem): def __init__(self): # run the __init__ of the inherted class BaseItem.__init__(self, None, None) # make some vertices self.vert = [[1,1,0],[1,-1,0],[-1,1,0],[-1,-1,0],[0,0,1]] self.color = [[1,1,0],[1,0,0],[0,1,0],[1,1,1],[0,0,1]] #set up opengl transformations # [translate [x,y,z] or [distance, [direction]], # rotate [x-axis,y-axis,z-axis], # scale [x,y,z] or real] self.transforms = [[0.,0.,0.],[0.,0.,0.],1.] # ^ probably better to implement as a dictionary with names for the transforms so that some can be left out without shifting all the other values def step(self): '''Items to animate the object''' pass def draw(self): # define the buffer and draw the points self.buffer = PointCloud(self.vert) #why can't i pass in color? self.buffer.sprite('data/particle.bmp') self.buffer.pointSize(50.0) self.buffer.draw() def move_obj(self, trans=[0,0,0]): vert = [] # this gives the new point locations for point in self.vert: new_point = [] for i,j in zip(point,trans): new_point.append(i+j) vert.append(new_point) self.vert = vert
class ParticleEngine(BaseEngine): def __init__(self): BaseEngine.__init__(self) def add_particle(self): self.particles.append(Particle(randint(400, 600), Vortex.random_vortex())) def draw(self): if not len(self.particles): return self.buffer = PointCloud([x.vortex.pos for x in self.particles], [x.color for x in self.particles]) self.buffer.sprite('data/particle.bmp') self.buffer.pointSize(105.0) self.buffer.draw() def spawn(self): if random() < 0.1: for _ in range(randint(1, 5)): self.add_particle()