diff --git a/.DS_Store b/.DS_Store
index 9a874b5..220c1c2 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/.gitignore b/.gitignore
index bc1671a..dd083b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -102,9 +102,24 @@ ENV/
# mypy
.mypy_cache/
+<<<<<<< HEAD
+<<<<<<< HEAD
+
+src/Render.py
+
+src/render.py
+
+src/render.py
+=======
+=======
+>>>>>>> master
.vscode/
.idea/boids.iml
.idea/boids.iml
.idea/misc.xml
*.iml
.idea/workspace.xml
+<<<<<<< HEAD
+>>>>>>> master
+=======
+>>>>>>> master
diff --git a/.idea/boids.iml b/.idea/boids.iml
deleted file mode 100644
index 1e7d6ae..0000000
--- a/.idea/boids.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 1fb1569..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 564ad09..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index 08bfdd2..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,553 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- DEFINITION_ORDER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1506705703762
-
-
- 1506705703762
-
-
- 1506705731276
-
-
-
- 1506705731276
-
-
- 1507134313562
-
-
-
- 1507134313562
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.DS_Store b/src/.DS_Store
index 53b9b02..5008ddf 100644
Binary files a/src/.DS_Store and b/src/.DS_Store differ
diff --git a/src/Behavior.py b/src/Behavior.py
index 7af9198..647b831 100644
--- a/src/Behavior.py
+++ b/src/Behavior.py
@@ -2,6 +2,23 @@
def behavior(boid):
+<<<<<<< HEAD
+<<<<<<< HEAD
+ max_acc = 1
+ r = 10
+ nby = [other for other in boid.flock.boids if boid.id > other.id and boid.flock.distance_matrix[boid.id][other.id] <
+ r or other.id > boid.id and boid.flock.distance_matrix[other.id][boid.id] < r]
+
+ # collision avoidance
+ threshold = 3
+ avoid = [other for other in nby if boid.id > other.id and boid.flock.distance_matrix[boid.id][other.id] < threshold
+ or other.id > boid.id and boid.flock.distance_matrix[other.id][boid.id] < threshold]
+ v1 = P3.P3(0, 0, 0)
+ for other in avoid:
+ v1 += other.position.vectorTo(boid.position) * (1 / boid.position.distance(other.position))
+=======
+=======
+>>>>>>> master
max_acc = .1
max_vel = 25
r = 200
@@ -14,20 +31,46 @@ def behavior(boid):
v1 = P3.P3(0, 0, 0)
for other in avoid:
v1 += other.position - boid.position * (1 / boid.position.distance(other.position)**2)
+<<<<<<< HEAD
+>>>>>>> master
+=======
+>>>>>>> master
# velocity matching
v2 = P3.P3(0, 0, 0)
for b in nby:
+<<<<<<< HEAD
+<<<<<<< HEAD
+ v2 += b.vel
+ if len(nby) > 1:
+ v2 *= 1/len(nby)
+=======
+=======
+>>>>>>> master
v2 += b.velocity
if len(nby) > 1:
v2 *= 1/len(nby)
v2 -= boid.velocity
+<<<<<<< HEAD
+>>>>>>> master
+=======
+>>>>>>> master
# flock centering
v3 = P3.P3(0, 0, 0)
for b in nby:
v3 += b.position
if len(nby) > 1:
+<<<<<<< HEAD
+<<<<<<< HEAD
+ v3 *= 1 / len(nby) # might need parenthesis around division
+
+ behavior_vel = 10*v1 + 1*v2 + 1*v3
+ delta_vel = behavior_vel + -1 * boid.vel
+ return P3.P3.normalize(delta_vel)
+=======
+=======
+>>>>>>> master
v3 *= 1 / len(nby)
v3 -= boid.position
@@ -42,3 +85,7 @@ def behavior(boid):
acc = P3.P3.normalize(delta_vel) * max_acc
return acc if acc.distance() < delta_vel.distance() else delta_vel
+<<<<<<< HEAD
+>>>>>>> master
+=======
+>>>>>>> master
diff --git a/src/Boid.py b/src/Boid.py
index fd96f44..b8f41f7 100644
--- a/src/Boid.py
+++ b/src/Boid.py
@@ -1,17 +1,49 @@
-import P3 # imports 3-D vector class
+import P3 # imports 3-D vector class
+import Behavior
class Boid:
+<<<<<<< HEAD
+<<<<<<< HEAD
+ def __init__(self, flock, id, position, vel, behavior):
+
+ self.id = id # holding a unique identifying int
+ self.position = position # P3 holding the position or (x, y, z) of the boid
+ self.vel = vel # P3 holding the velosities of the boid
+ self.behavior = behavior # Float holding the acceleration
+=======
+ def __init__(self, flock, id, position, velocity, behavior):
+
+ self.id = id # holding a unique identifying int
+ self.position = position # P3 holding the position or (x, y, z) of the boid
+ self.velocity = velocity # P3 holding the velosities of the boid
+ self.behavior = behavior # Float holding the behavior function
+>>>>>>> master
+=======
def __init__(self, flock, id, position, velocity, behavior):
self.id = id # holding a unique identifying int
self.position = position # P3 holding the position or (x, y, z) of the boid
self.velocity = velocity # P3 holding the velosities of the boid
self.behavior = behavior # Float holding the behavior function
+>>>>>>> master
self.flock = flock # Current flock holding boid object
def move_Boid(self, tick): # Called to change the velocity and position of a particuliar boid
+<<<<<<< HEAD
+<<<<<<< HEAD
+ self.vel = self.vel + self.behavior(self) * tick # Update velocity by adding the acceleration and multiplying by the tick
+
+ self.position = self.position + self.vel * tick # Update position by adding the velocity and multiplying by the tick
+
+=======
+ self.velocity = self.velocity + self.behavior(self) * tick # Update velocity by calling behavior function and multiplying by the tick
+
+ self.position = self.position + self.velocity * tick # Update position by adding the velocity and multiplying by the tick
+>>>>>>> master
+=======
self.velocity = self.velocity + self.behavior(self) * tick # Update velocity by calling behavior function and multiplying by the tick
self.position = self.position + self.velocity * tick # Update position by adding the velocity and multiplying by the tick
+>>>>>>> master
diff --git a/src/Flock.py b/src/Flock.py
index 544fb26..d2ad326 100644
--- a/src/Flock.py
+++ b/src/Flock.py
@@ -3,6 +3,7 @@
import P3
import math
import random
+import Behavior
class Flock:
@@ -19,11 +20,21 @@ def __init__(self, num_boids, center=P3.P3(0, 0, 0), radius=20): #possibly also
theta = 2 * math.pi * random.random()
x = r * math.cos(theta)
y = r * math.sin(theta)
+<<<<<<< HEAD
+<<<<<<< HEAD
+ self.boids.append(Boid.Boid(self, i, P3.P3(x, y, 50) + center, P3.P3(5, 0, 0), Behavior.behavior))
+=======
+=======
+>>>>>>> master
# eventually velocity is taken from config file
v = P3.P3(1*random.random()*random.randrange(-1, 2, 2)+5, 1*random.random()*random.randrange(-1, 2, 2)+5, 0)
self.boids.append(Boid.Boid(self, i, P3.P3(x, y, 0) + center + P3.P3(0, 0, 2*random.randrange(-5, 6, 10)),
v, Behavior.behavior))
self.update_dist_matrix()
+<<<<<<< HEAD
+>>>>>>> master
+=======
+>>>>>>> master
def update(self, tick):
for b in self.boids:
diff --git a/src/P3.py b/src/P3.py
index 2da30b9..e836a82 100644
--- a/src/P3.py
+++ b/src/P3.py
@@ -30,6 +30,9 @@ def normalize(self):
magnitude = self.distance() if self.distance() != 0 else 1
return P3(self.x/magnitude, self.y/magnitude, self.z/magnitude)
+ def vectorTo(self, other):
+ return P3(other.x-self.x, other.y-self.y, other.z-self.z)
+
def __str__(self):
return '(' + str(self.x) + ', ' + str(self.y) + ', ' + str(self.z) + ')'
@@ -37,6 +40,9 @@ def __str__(self):
if __name__ == "__main__":
p1 = P3(1, 1, 1)
p2 = P3(2, 5, 10)
+
+
+
print(2 * p1)
print(p1 * 2)
print(p1 * p2)
@@ -49,3 +55,4 @@ def __str__(self):
print(p3 - p1)
+ print(P3.normalize(p2))
diff --git a/src/render.py b/src/render.py
index 2a70025..b20de1b 100644
--- a/src/render.py
+++ b/src/render.py
@@ -8,10 +8,9 @@
import Flock
import Boid
import P3
+import os
+
-x = 800
-y = 600
-z = 1000
@@ -46,7 +45,8 @@
)
#call to create display
-def start(width, hieght, depth):
+def start(x, y, width, hieght, depth):
+ os.environ['SDL_VIDEO_WINDOW_POS'] = str(x) + "," + str(y)
pygame.init()
display = (width, hieght)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
@@ -107,20 +107,13 @@ def draw_bird(vertices):
glEnd()
- glBegin(GL_LINES)
- for edge in edges:
- for vertex in edge:
- glColor3fv((1, 1, 1))
- glVertex3fv(vertices[vertex])
- glEnd()
-
#call to create a new building
class Buildings(object):
- _registry = []
+ registry = []
def __init__(self, x, y, width, height, depth, color):
- self._registry.append(self)
+ self.registry.append(self)
self.x = x
self.y = y
self.width = width
@@ -134,22 +127,8 @@ def set_building(self):
final_vertices = []
global building_count
- #positoning
- for vert in building_vertices:
- new_vert = []
-
- new_x = vert[0] + self.x
- new_y = vert[1] + self.y
- new_z = vert[2]
-
- new_vert.append(new_x)
- new_vert.append(new_y)
- new_vert.append(new_z)
-
- new_vertices.append(new_vert)
-
#scaling
- for nvert in new_vertices:
+ for nvert in building_vertices:
fnew_vert = []
newv_x = nvert[0] * self.width
@@ -160,7 +139,21 @@ def set_building(self):
fnew_vert.append(newv_y)
fnew_vert.append(newv_z)
- final_vertices.append(fnew_vert)
+ new_vertices.append(fnew_vert)
+
+ #positoning
+ for vert in new_vertices:
+ new_vert = []
+
+ new_x = vert[0] + self.x
+ new_y = vert[1] + self.y
+ new_z = vert[2]
+
+ new_vert.append(new_x)
+ new_vert.append(new_y)
+ new_vert.append(new_z)
+
+ final_vertices.append(new_vert)
return final_vertices
@@ -220,7 +213,7 @@ def draw(self):
ground()
- for building in Buildings._registry:
+ for building in Buildings.registry:
Buildings.draw_building(building)
for b in self.flock.boids:
@@ -241,7 +234,7 @@ def draw(self):
f = Render(flock)
for num in range(10):
- Buildings(random.randrange(-10, 10), random.randrange(-10, 10), random.randrange(1, 10), random.randrange(1, 10), random.randrange(1, 10), (random.randrange(0,2), random.randrange(0,2), random.randrange(0,2)))
+ Buildings(random.randrange(-100, 100), random.randrange(-100, 100), random.randrange(1, 10), random.randrange(1, 10), random.randrange(1, 10), (random.randrange(0,2), random.randrange(0,2), random.randrange(0,2)))
start(800, 600, 1000)