import sys, time, math, os, random from euclid import * from pyglet.gl import * window = pyglet.window.Window() objects = [] GRAV = Vector2(0,-100) class Square: def __init__(self, width, height, xpos, ypos, color): self.pos = Vector2(random.uniform(200,300), random.uniform(220,480)) a = random.uniform(0,2*math.pi) self.vel = Vector2(math.cos(a),math.sin(a)) * 100 self.color = color x = width/2.0 y = height/2.0 self.vlist = pyglet.graphics.vertex_list(4, ('v2f', [-x,-y, x,-y, -x,y, x,y]), ('t2f', [0,0, 1,0, 0,1, 1,1])) def draw(self): glPushMatrix() glTranslatef(self.pos[0], self.pos[1], 0) self.vlist.draw(GL_TRIANGLE_STRIP) glPopMatrix() def move(self,dt): self.vel = self.vel + GRAV * dt self.pos = self.pos + self.vel * dt class ParticleSystem: def __init__(self): self.particles = [] for i in range(250): square1 = Square(120, 120, 300, 200, [1,1,1]) self.particles.append(square1) self.texture = pyglet.image.load("drop.png").get_texture() def draw(self): glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, self.texture.id) glColor3f(1,1,1) for p in self.particles: p.draw() glDisable(GL_TEXTURE_2D) def update(self,dt): for p in self.particles: p.move(dt) @window.event def on_draw(): global objects glClearColor(0, 0, 0, 0) glClear(GL_COLOR_BUFFER_BIT) glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE) for o in objects: o.draw() @window.event def on_key_press(key,modifiers): pass starttime = time.time() def update(dt): global objects for o in objects: o.update(dt) objects.append(ParticleSystem()) pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()