def setup(): size(400, 300) global fountain global field field_strength = 4 field = FlowField(field_strength) fountain = ParticleSystem()
def setup(): size(800, 600) global vehicles global path vehicles = ParticleSystem() path = Path() path.populate()
def main(): if len(sys.argv) < 2: terminate_with_usage() n_particles = parse_number(sys.argv[1]) if n_particles <= 0: terminate_with_usage() try: particle_system = ParticleSystem(n_particles) particle_system.loop() except IOError as e: print(Style.BRIGHT + Fore.RED + 'I/O Error: ' + Style.RESET_ALL + Fore.RESET + str(e)) except ParticleSystemException as e: print(Style.BRIGHT + Fore.RED + 'ParticleSystemException: ' + Style.RESET_ALL + Fore.RESET + str(e))
def __init__(self): # All of our regular motion stuff self.position = PVector(width/2, height/2) self.velocity = PVector() self.acceleration = PVector() # Arbitrary damping to slow down ship self.damping = 0.995 self.topspeed = 6 # Are we thursting (to color the boosters) self.thrusting = False # Variable for heading! self.heading = 0 # Size self.r = 16 self.ps = ParticleSystem()
class Spaceship(object): def __init__(self): # All of our regular motion stuff self.position = PVector(width/2, height/2) self.velocity = PVector() self.acceleration = PVector() # Arbitrary damping to slow down ship self.damping = 0.995 self.topspeed = 6 # Are we thursting (to color the boosters) self.thrusting = False # Variable for heading! self.heading = 0 # Size self.r = 16 self.ps = ParticleSystem() def update(self): """Standard Euler integration""" self.velocity.add(self.acceleration) self.velocity.mult(self.damping) self.velocity.limit(self.topspeed) self.position.add(self.velocity) self.acceleration.mult(0) self.ps.run() def applyForce(self, force): """Newton's law: F = M * A""" f = force.get() # ignoring mass right now # f.div(mass) self.acceleration.add(f) def turn(self, a): """Turn changes angle""" self.heading += a def thrust(self): """Apply a thrust force""" # Offset the angle since we drew the ship vertically angle = self.heading - PI/2 # Polar to cartesian for force vector! force = PVector(cos(angle),sin(angle)) force.mult(0.1) self.applyForce(force) force.mult(-2) self.ps.add_particle(self.position.x, \ self.position.y+self.r, \ force) # To draw booster self.thrusting = True def wrapEdges(self): wrap_buffer = self.r * 2 if self.position.x > (width + wrap_buffer): self.position.x = -wrap_buffer elif self.position.x < (-wrap_buffer): self.position.x = width + wrap_buffer if self.position.y > (height + wrap_buffer): self.position.y = -wrap_buffer elif self.position.y < (-wrap_buffer): self.position.y = height + wrap_buffer def display(self): """Draw the ship""" stroke(0) strokeWeight(2) pushMatrix() translate(self.position.x, self.position.y+self.r) rotate(self.heading) fill(175) if self.thrusting: fill(255,0,0) # Booster rockets rect(-self.r/2,self.r, self.r/3, self.r/2) rect(self.r/2,self.r, self.r/3, self.r/2) fill(175) # A triangle beginShape() vertex(-self.r, self.r) vertex(0, -self.r) vertex(self.r, self.r) endShape(CLOSE) rectMode(CENTER) popMatrix() self.thrusting = False
def setup(): size(498,298) global vehicles vehicles = ParticleSystem()
class Cell(object): """ generated source for class Cell """ sys = ParticleSystem() particles = ArrayList() neighbors = [] origin = PVector() def __init__(self, sys, x, y): """ generated source for method __init__ """ self.sys = sys self.particles = ArrayList() self.origin = PVector(CELL_SIZE * x, CELL_SIZE * y) def plan(self): """ generated source for method plan """ for p in self.particles: for cell in self.neighbors: if cell == None: continue force.add(cell.repel(p)) force.limit(1.0) p.plan(force) def move(self): """ generated source for method move """ i = len(self.particles) - 1 while i >= 0: p.move() if not self.contains(p.origin.x, p.origin.y): self.remove(p) self.sys.place(p) i -= 1 def draw(self): """ generated source for method draw """ for p in self.particles: p.draw() debugDraw() def debugDraw(self): """ generated source for method debugDraw """ if not DEBUG: return noFill() stroke(255, 0, 0) strokeWeight(1) rect(self.origin.x, self.origin.y, CELL_SIZE, CELL_SIZE) def add(self, p): """ generated source for method add """ self.particles.add(p) def remove(self, p): """ generated source for method remove """ self.particles.remove(p) def repel(self, p): """ generated source for method repel """ sum = PVector(0, 0) dist = float() unit = PVector() for other in self.particles: if other == p: continue dist = PVector.dist(p.origin, other.origin) if dist > CELL_SIZE: continue unit = PVector.sub(p.origin, other.origin) unit.normalize() dist = norm(dist, 0, CELL_SIZE) unit.mult((p.mass * other.mass) / (dist * dist)) sum.add(unit) return sum def contains(self, x, y): """ generated source for method contains """ dx = x - self.origin.x if dx < 0 or dx > CELL_SIZE: return False dy = y - self.origin.y if dy < 0 or dy > CELL_SIZE: return False return True
def setup(): size(900, 900) global vehicles vehicles = ParticleSystem()
def setup(): size(80, 60) global vehicles global path vehicles = ParticleSystem() path = Path()