import sys sys.path.append('/Users/apollotiger/lib') import particle import euclid import copy size(400,400) speed(100) def setup(): global particles,frame frame = 0 particles = [] origpositions = [] while len(particles) < 20: newparticle = particle.Particle(euclid.Vector2(random(12,WIDTH-12), random(12,HEIGHT-12)),12,7,0) newparticle.velocity = euclid.Vector2(random(0,200) / 100.0, random(0,200) / 100.0) particles.append(newparticle) fill(0,0,255) def draw(): global particles,frame,origpositions frame += 1 print frame for p in particles: p.position += p.velocity if not (WIDTH - p.radius > p.position.x > p.radius): p.velocity.x *= -1 p.position.x = (WIDTH - p.radius if WIDTH - p.radius < p.position.x else p.radius) if not (HEIGHT - p.radius > p.position.y > p.radius): p.velocity.y *= -1 p.position.y = (HEIGHT - p.radius if HEIGHT - p.radius < p.position.y else p.radius) for np in particles: if np != p: if abs(np.position - p.position) < (np.radius + p.radius): # COLLISION! print "COLLISION" print abs(p.origposition - p.position) print abs(np.origposition - np.position) p.origposition = copy.copy(p.position) np.origposition = copy.copy(np.position) oval(p.position.x,p.position.y,p.radius,p.radius)