Skip to content

Commit

Permalink
version that doesn't depend on numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
jdchambers committed Aug 19, 2012
1 parent 3fc0367 commit 1104c99
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 159 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.pyc
.DS_Store
.idea
14 changes: 8 additions & 6 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ class World(object):
verts = [0.5, 0.0,-0.5, -0.2,-0.5, 0.2]
vertsGl = (GLfloat * len(verts))(*verts)

def __init__(self, swarm):
def __init__(self, swarm, offx, offy):
self.swarm = swarm
self.ents = swarm.boids #this will point to a list of boids
self.ent_size=15.0
self.fps = clock.ClockDisplay()
self.o_x = offx
self.o_y = offy

def draw_entity(self,ent):
def draw_entity(self,e):
""" Draws a boid """
glLoadIdentity()
glTranslatef(ent.x, ent.y, 0.0)
glRotatef(ent.rotation*180/pi, 0, 0, 1)
glTranslatef(e.position.x+self.o_x, e.position.y+self.o_y, 0.0)
glRotatef(e.rotation*180/pi, 0, 0, 1)
glScalef(self.ent_size, self.ent_size, 1.0)
glColor4f(0,0,0,0)
glEnableClientState(GL_VERTEX_ARRAY)
Expand Down Expand Up @@ -85,8 +87,8 @@ def draw(self):
for ent in self.ents:
self.draw_entity(ent)

simulation = optboids.FlockSimulation(200)
world = World(simulation.swarm)
simulation = optboids.FlockSimulation(200,600)
world = World(simulation.swarm,50,50)

window = pyglet.window.Window(800, 750, vsync=True)

Expand Down
4 changes: 4 additions & 0 deletions euclid.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def __abs__(self):

magnitude = __abs__

def clear(self):
self.x = 0
self.y = 0

def magnitude_squared(self):
return self.x ** 2 + \
self.y ** 2
Expand Down
Loading

0 comments on commit 1104c99

Please sign in to comment.