From ecf2a716dbbca3db8856a35470b313d0b7ccdee7 Mon Sep 17 00:00:00 2001 From: micascheid Date: Mon, 2 Oct 2017 11:45:35 -0600 Subject: [PATCH 01/18] Flock and renderer draft --- .gitignore | 6 ++++++ src/Boid.py | 2 +- src/Flock.py | 6 ++++-- src/render.py | 57 +++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 7bbc71c..6355656 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,9 @@ ENV/ # mypy .mypy_cache/ + +src/Render.py + +src/render.py + +src/render.py diff --git a/src/Boid.py b/src/Boid.py index 7a55457..4bd547a 100644 --- a/src/Boid.py +++ b/src/Boid.py @@ -2,7 +2,7 @@ class Boid: - def __init__(self, id, position, vel, acc = 0, flock): + def __init__(self, id, position, vel, acc, flock): self.id = id # holding a unique identifying int self.position = position # P3 holding the position or (x, y, z) of the boid diff --git a/src/Flock.py b/src/Flock.py index 058a315..21902f3 100644 --- a/src/Flock.py +++ b/src/Flock.py @@ -8,7 +8,7 @@ class Flock: def __init__(self, num_boids, center, radius): #possibly also orientation, maybe something about obstacles? self.num_boids = num_boids self.boids = [] - Flock.flock_count += 1 + #Flock.flock_count += 1 self.distance_matrix = [[0 for _ in range(num_boids)] for _ in range(num_boids)] # defaults boid to grid @@ -16,7 +16,9 @@ def __init__(self, num_boids, center, radius): #possibly also orientation, maybe for i in range(num_boids): if i % 10 == 0: row += 1 - self.boids.append(Boid(i, P3(200 + 10 * row, -20 + 4 * i, 50), P3(-15, 0, 0), P3(0, 0, 0), self)) + self.boids.append(Boid.Boid(i, P3.P3(200 + 10 * row, -20 + 4 * i, 50), P3.P3(-15, 0, 0), P3.P3(0, 0, 0), self)) + # self.boids.append(Boid.Boid(i, P3.P3(0 + 10 * row, i, 20 - 4 * i), P3.P3(-5, 0, 0), P3.P3(0, 0, 0), self)) + def update(self, tick): for b in self.boids: diff --git a/src/render.py b/src/render.py index 583a4fe..210004a 100644 --- a/src/render.py +++ b/src/render.py @@ -4,6 +4,8 @@ from OpenGL.GLU import * from OpenGL.GLUT import * import random +import Flock +import Boid x = 800 y = 600 @@ -26,6 +28,16 @@ (-100, -.10, -10), (100, -.10, -10) ) +buidling_vertices = ( + (0,0,1),#0 + (1,0,1),#1 + (0,0,0),#2 + (1,0,0),#3 + (0,1,1),#4 + (1,1,1),#5 + (0,1,0),#6 + (1,1,0)#7 + ) #draws the ground (render use only) @@ -41,7 +53,7 @@ def ground(): def update_birds(birdNum): thisVelocity = bird_velocity_dict[birdNum] thisBird = bird_dict[birdNum] - + print(thisBird) #changes the position of the birds vertices for vert in thisBird: vert[0] = vert[0] + thisVelocity[0] #x value @@ -76,6 +88,34 @@ def bird(vertices): def bird_velocity(x_velocity, y_velocity, z_velocity, birdNum): bird_velocity_dict[birdNum] = [x_velocity, y_velocity, z_velocity] +def buidling(vertices): + edges = ( + (0, 1), + (0, 4), + (1, 2), + (1, 5), + (2, 3), + (2, 6), + (3, 0), + (3, 7), + (4, 5), + (5, 6), + (6, 7), + (7, 4) + ) + for edge in edges: + for vertex in edge: + glColor3fv((1,1,1)) + glVertex3fv(vertices[vertex]) + glEnd() + +def set_building(x, y, z, width, height, depth, color): + new_vertices = [] + + + + + return #initializes birds at a given x, y, z (call add a bird) def set_bird_vertices(x, y, z): @@ -105,7 +145,7 @@ def start(width, hieght, depth): display = (width, hieght) pygame.display.set_mode(display, DOUBLEBUF | OPENGL) - gluPerspective(45, (display[0]/display[1]), 0.1, depth) + gluPerspective(45 , (display[0]/display[1]), 0.1, depth) #glTranslatef(0, 0, 0) @@ -132,11 +172,16 @@ def draw(): if __name__ == "__main__": - for num in range(100): - set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) + #for num in range(100): + #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) + flock = Flock.Flock(100, 0, 0) + # for b in flock.boids: + for i in range(len(flock.boids)): + set_bird_vertices(flock.boids[i].position.x, flock.boids[i].position.y, flock.boids[i].position.z) + bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) start(800, 600, 150) - for num in range(100): - bird_velocity(random.randrange(-5, 5), random.randrange(-5, 5), random.randrange(-5, 5), num) + # for num in range(100): + # bird_velocity(random.randrange(-5, 5), random.randrange(-5, 5), random.randrange(-5, 5), num) while True: draw() From b9896fd6723b430e18d76989e170161bab828bc1 Mon Sep 17 00:00:00 2001 From: micascheid Date: Mon, 2 Oct 2017 12:16:51 -0600 Subject: [PATCH 02/18] Merge branch 'master' into renderer # Conflicts: # src/Boid.py --- src/render.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/render.py b/src/render.py index 210004a..36049f6 100644 --- a/src/render.py +++ b/src/render.py @@ -3,6 +3,7 @@ from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * + import random import Flock import Boid @@ -168,14 +169,20 @@ def draw(): pygame.display.flip() +def get_Flock(flock): + flock = flock + return flock + +flock = get_Flock() if __name__ == "__main__": #for num in range(100): #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) - flock = Flock.Flock(100, 0, 0) + #flock = Flock.Flock(100, 0, 0) # for b in flock.boids: + for i in range(len(flock.boids)): set_bird_vertices(flock.boids[i].position.x, flock.boids[i].position.y, flock.boids[i].position.z) bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) @@ -185,3 +192,4 @@ def draw(): while True: draw() + From dfa9ced94a221a56d86f68ccd267c670dd1e343f Mon Sep 17 00:00:00 2001 From: micascheid Date: Tue, 3 Oct 2017 15:29:34 -0600 Subject: [PATCH 03/18] Scene update --- src/render.py | 145 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 109 insertions(+), 36 deletions(-) diff --git a/src/render.py b/src/render.py index 36049f6..064f070 100644 --- a/src/render.py +++ b/src/render.py @@ -15,38 +15,48 @@ bird_count = 0 bird_dict = {} bird_velocity_dict = {} +building_dict = {} +building_count = 0 +color_list = [] bird_vertices = ( (0, 0, 0), - (0, .25, 1), - (-1, 0, 1), - (0, -.25, 1), - (1, 0, 1) + (0, 1, .25), + (-1, 1, 0), + (0, 1, -.25), + (1, 1, 0) ) ground_vertices = ( - (-100, -.1, 250), - (100, -.1, 250), - (-100, -.10, -10), - (100, -.10, -10) + (-100, 100, -.1), + (100, 100, -.1), + (-100, -100, -.1), + (100, -100, -.1) ) -buidling_vertices = ( - (0,0,1),#0 - (1,0,1),#1 - (0,0,0),#2 - (1,0,0),#3 - (0,1,1),#4 - (1,1,1),#5 - (0,1,0),#6 - (1,1,0)#7 +ground_edges = ( + (0, 1), + (1, 3), + (3, 2), + (2, 0) +) +building_vertices = ( + (0,0,0),#0 + (1,0,0),#1 + (1,0,-1),#2 + (0,0,-1),#3 + (0,1,0),#4 + (1,1,0),#5 + (1,1,-1),#6 + (0,1,-1)#7 ) #draws the ground (render use only) def ground(): glBegin(GL_QUADS) - for verts in ground_vertices: - glColor3fv((0,.5,.5)) - glVertex3fv(verts) + for edges in ground_edges: + for vert in edges: + glColor3fv((0,.5,.5)) + glVertex3fv(ground_vertices[vert]) glEnd() @@ -54,7 +64,7 @@ def ground(): def update_birds(birdNum): thisVelocity = bird_velocity_dict[birdNum] thisBird = bird_dict[birdNum] - print(thisBird) + #print(thisBird) #changes the position of the birds vertices for vert in thisBird: vert[0] = vert[0] + thisVelocity[0] #x value @@ -67,7 +77,7 @@ def update_birds(birdNum): #used to display birds (render use only) def bird(vertices): edges = ( - (0, 1), + (0, 1), (0, 2), (0, 3), (0, 4), @@ -89,7 +99,7 @@ def bird(vertices): def bird_velocity(x_velocity, y_velocity, z_velocity, birdNum): bird_velocity_dict[birdNum] = [x_velocity, y_velocity, z_velocity] -def buidling(vertices): +def building(vertices, color): edges = ( (0, 1), (0, 4), @@ -104,19 +114,67 @@ def buidling(vertices): (6, 7), (7, 4) ) + surfaces = ( + (0,1,2,3), + (2,6,5,1), + (0,1,4,5), + (0,3,7,4), + (3,7,6,2), + (7,4,5,6) + ) + glBegin(GL_QUADS) + for surface in surfaces: + for vertex in surface: + glColor3fv(color) + glVertex3fv(vertices[vertex]) + glEnd() + + + glBegin(GL_LINES) for edge in edges: for vertex in edge: - glColor3fv((1,1,1)) + glColor3fv((1, 1, 1)) glVertex3fv(vertices[vertex]) glEnd() -def set_building(x, y, z, width, height, depth, color): + +def set_building(bx, by, bz, width, height, depth): new_vertices = [] + final_vertices = [] + global building_count + + #positoning + for vert in building_vertices: + new_vert = [] + new_x = vert[0] + bx + new_y = vert[1] + by + new_z = vert[2] + bz + 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: + fnew_vert = [] + + newv_x = nvert[0] * width + newv_y = nvert[1] * depth + newv_z = nvert[2] * height + + fnew_vert.append(newv_x) + fnew_vert.append(newv_y) + fnew_vert.append(newv_z) + + final_vertices.append(fnew_vert) + + building_dict[building_count] = final_vertices + building_count += 1 + color_list.append(color) - return #initializes birds at a given x, y, z (call add a bird) def set_bird_vertices(x, y, z): @@ -146,8 +204,9 @@ def start(width, hieght, depth): display = (width, hieght) pygame.display.set_mode(display, DOUBLEBUF | OPENGL) - gluPerspective(45 , (display[0]/display[1]), 0.1, depth) - #glTranslatef(0, 0, 0) + gluPerspective(45, (display[0]/display[1]), 0.1, depth) + glTranslatef(-10, 30, -250) + glRotatef(-45, 1, 1, 1) #draws objects on screen (call each tick of the clock) @@ -159,6 +218,7 @@ def draw(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + ground() for each_bird in bird_velocity_dict: @@ -167,28 +227,41 @@ def draw(): for each_bird in bird_dict: bird(bird_dict[each_bird]) + for each_building in building_dict: + building(building_dict[each_building], color_list[each_building]) + #print(each_building) + + + pygame.display.flip() -def get_Flock(flock): - flock = flock - return flock -flock = get_Flock() + if __name__ == "__main__": #for num in range(100): #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) - #flock = Flock.Flock(100, 0, 0) + flock = Flock.Flock(100, 0, 0) # for b in flock.boids: for i in range(len(flock.boids)): - set_bird_vertices(flock.boids[i].position.x, flock.boids[i].position.y, flock.boids[i].position.z) + set_bird_vertices(flock.boids[i].position.x, flock.boids[i].position.y, -(flock.boids[i].position.z)) bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) - start(800, 600, 150) + start(800, 600, 1000) # for num in range(100): - # bird_velocity(random.randrange(-5, 5), random.randrange(-5, 5), random.randrange(-5, 5), num) + # bird_velocity(flock.boids[num], random.randrange(-5, 5), random.randrange(-5, 5), num) + + + for num in range(10): + color = (random.randrange(0, 2), random.randrange(0, 2), random.randrange(0, 2)) + color_list.append(color) + + for num in range(10): + set_building(random.randrange(-10,10), random.randrange(-10,10), 0,random.randrange(2,20) , random.randrange(2,20), random.randrange(2,20)) + + while True: draw() From c85964953f6b0338f6d892f961dfe941a18f75dd Mon Sep 17 00:00:00 2001 From: micascheid Date: Tue, 3 Oct 2017 16:22:02 -0600 Subject: [PATCH 04/18] Updates to renderer --- src/render.py | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/render.py b/src/render.py index 064f070..1b025dc 100644 --- a/src/render.py +++ b/src/render.py @@ -18,6 +18,7 @@ building_dict = {} building_count = 0 color_list = [] +boid_dict = {} bird_vertices = ( (0, 0, 0), @@ -75,7 +76,7 @@ def update_birds(birdNum): #used to display birds (render use only) -def bird(vertices): +def draw_bird(vertices): edges = ( (0, 1), (0, 2), @@ -177,25 +178,28 @@ def set_building(bx, by, bz, width, height, depth): #initializes birds at a given x, y, z (call add a bird) -def set_bird_vertices(x, y, z): +def make_bird_vertices(bird): new_vertices = [] global bird_count for vert in bird_vertices: new_vert = [] - new_x = vert[0] + x - new_y = vert[1] + y - new_z = vert[2] + z + new_x = vert[0] + bird.position.x + new_y = vert[1] + bird.position.y + new_z = vert[2] + bird.position.z new_vert.append(new_x) new_vert.append(new_y) new_vert.append(new_z) + # new_vertices.append(new_vert) new_vertices.append(new_vert) - bird_dict[bird_count] = new_vertices - bird_count += 1 + + #bird_dict[bird_count] = new_vertices + #bird_count += 1 + return new_vertices #initiates display window (call one time to start display) @@ -221,15 +225,18 @@ def draw(): ground() - for each_bird in bird_velocity_dict: - update_birds(each_bird) - - for each_bird in bird_dict: - bird(bird_dict[each_bird]) - + # for each_bird in bird_velocity_dict: + # update_birds(each_bird) + # + # for each_bird in bird_dict: + # bird(bird_dict[each_bird]) + # for each_building in building_dict: building(building_dict[each_building], color_list[each_building]) - #print(each_building) + + for b in flock.boids: + v = make_bird_vertices(b) + draw_bird(v) @@ -245,13 +252,16 @@ def draw(): #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) flock = Flock.Flock(100, 0, 0) # for b in flock.boids: - - for i in range(len(flock.boids)): - set_bird_vertices(flock.boids[i].position.x, flock.boids[i].position.y, -(flock.boids[i].position.z)) - bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) start(800, 600, 1000) + + for i in range(100): + draw() + #make_bird_vertices(flock.boids[i]) + #bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) + + # for num in range(100): - # bird_velocity(flock.boids[num], random.randrange(-5, 5), random.randrange(-5, 5), num) + # bird_velocity(random.randrange(-5, 5), random.randrange(-5, 5), random.randrange(-5, 5), num) for num in range(10): From 6cd84b36d558edbfaca69d62e3dc17c113079c51 Mon Sep 17 00:00:00 2001 From: micascheid Date: Tue, 3 Oct 2017 16:30:45 -0600 Subject: [PATCH 05/18] Merge branch 'master' into renderer # Conflicts: # src/Boid.py # src/Flock.py --- src/Boid.py | 44 ++++++++++++++------------------------------ src/Flock.py | 39 +++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/src/Boid.py b/src/Boid.py index 4bd547a..746e702 100644 --- a/src/Boid.py +++ b/src/Boid.py @@ -1,33 +1,17 @@ -import P3 # imports 3-D vector class +import P3 # imports 3-D vector class class Boid: - - def __init__(self, id, position, vel, acc, flock): - - 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.acc = acc # Float holding the acceleration - self.flock = flock # Current flock holding boid object - - def move_Boid(self, tick): # Called to change the velocity and position of a particuliar boid - - self.vel = self.vel + acc * tick # Add the acceleration and add it to the boid's velocity - - self.position = self.position + self.vel * tick # Update position by adding the velocity and multiplying by the tick - - - - - - - - - - - - - - - + def __init__(self, flock, id, position, vel, acc=P3.P3(0, 0, 0)): + + 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.acc = acc # Float holding the acceleration + self.flock = flock # Current flock holding boid object + + def move_Boid(self, tick): # Called to change the velocity and position of a particuliar boid + + self.vel = self.vel + self.acc * 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 diff --git a/src/Flock.py b/src/Flock.py index 21902f3..c4e1441 100644 --- a/src/Flock.py +++ b/src/Flock.py @@ -1,31 +1,38 @@ import Boid import P3 +import math +import random class Flock: - flockcount = 0 - - def __init__(self, num_boids, center, radius): #possibly also orientation, maybe something about obstacles? - self.num_boids = num_boids + flock_count = 0 + + def __init__(self, num_boids, center=P3.P3(0, 0, 0), + radius=20): # possibly also orientation, maybe something about obstacles? + Flock.flock_count += 1 self.boids = [] - #Flock.flock_count += 1 self.distance_matrix = [[0 for _ in range(num_boids)] for _ in range(num_boids)] - # defaults boid to grid - row = -1 + # randomly distributes boids in circle on xy plane using center and radius for i in range(num_boids): - if i % 10 == 0: - row += 1 - self.boids.append(Boid.Boid(i, P3.P3(200 + 10 * row, -20 + 4 * i, 50), P3.P3(-15, 0, 0), P3.P3(0, 0, 0), self)) - # self.boids.append(Boid.Boid(i, P3.P3(0 + 10 * row, i, 20 - 4 * i), P3.P3(-5, 0, 0), P3.P3(0, 0, 0), self)) - + r = radius * math.sqrt(random.random()) + theta = 2 * math.pi * random.random() + x = r * math.cos(theta) + y = r * math.sin(theta) + self.boids.append(Boid.Boid(self, i, P3.P3(x, y, 50) + center, P3.P3(-5, 0, 0), P3.P3(0, 0, 0))) def update(self, tick): for b in self.boids: - b.self.move_Boid(self.distance_matrix, tick) - self.dist_matrix() + b.move_Boid(self.distance_matrix, tick) + self.update_dist_matrix() - def dist_matrix(self): + def update_dist_matrix(self): for i in range(len(self.boids)): - for j in range(len(self.boids) - i-1): + for j in range(len(self.boids) - i - 1): self.distance_matrix[i][j] = self.boids[i].position.distance(self.boids[j].position) + + +if __name__ == '__main__': + flock = Flock(10, P3.P3(100, 100, 1), 1) + for b in flock.boids: + print(b.position) \ No newline at end of file From 7e58d178c65dde4e9070ef3738fdbb7de7a48497 Mon Sep 17 00:00:00 2001 From: micascheid Date: Wed, 4 Oct 2017 11:08:41 -0600 Subject: [PATCH 06/18] Ready to make an init --- .DS_Store | Bin 6148 -> 6148 bytes src/.DS_Store | Bin 6148 -> 6148 bytes src/Behavior.py | 34 ++++++++++++++++++++++++++++++++++ src/Boid.py | 8 ++++---- src/Flock.py | 5 +++-- src/P3.py | 8 ++++++-- src/render.py | 22 ++++++++++++---------- 7 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 src/Behavior.py diff --git a/.DS_Store b/.DS_Store index 9a874b5768f336915163bb88cd434575b859f936..220c1c2cdfc67b69cd7b97f6d1a94f5743e0a976 100644 GIT binary patch delta 145 zcmZoMXfc=|&e%3FQH+&?fq{WzVxou)6OaJ{AexbZL4YASCn-Na2gqb#o|vei1rldw zC}t>PNKPq6l7k491sCPzG;d4{VxMdv!m^p0gNK8$ZDZnh=E?jbilQJB6o5DZ Qh(X340AhyCjw1V+0l-Qdp8x;= delta 108 zcmZoMXfc=|&Zs)EP}qc#fq{XUp_rkFAvvWuIVUMUKL;cP224;IBml$$3{d%v2i@2w pUP#)^&LP0TsJijscjn3bB8r?KWeFfHlTCP(Hz$ZJVV>B)0sxkP7PbHY diff --git a/src/.DS_Store b/src/.DS_Store index 53b9b02c2c6edade61f301ca04ab65daf2114163..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100644 GIT binary patch delta 51 vcmZoMXfc?e&B4IH0LBvwMFg0D92j6^U=Y|?IE{T`gVbaL5thx|96$L1%DD*$ delta 76 zcmZoMXfc?eJ=s8n#e|iioFSi~h#`j|C8anyCn-NahmipYm_P&&fH*)bzwhy LNb_cHj-UJhdDal* diff --git a/src/Behavior.py b/src/Behavior.py new file mode 100644 index 0000000..9afcfec --- /dev/null +++ b/src/Behavior.py @@ -0,0 +1,34 @@ +import P3 + + +def behavior(boid): + 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)) + + # velocity matching + v2 = P3.P3(0, 0, 0) + for b in nby: + v2 += b.vel + if len(nby) > 1: + v2 *= 1/len(nby) + + # flock centering + v3 = P3.P3(0, 0, 0) + for b in nby: + v3 += b.position + if len(nby) > 1: + 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) \ No newline at end of file diff --git a/src/Boid.py b/src/Boid.py index b2745e9..8393f1d 100644 --- a/src/Boid.py +++ b/src/Boid.py @@ -1,19 +1,19 @@ import P3 # imports 3-D vector class - +import Behavior class Boid: - def __init__(self, flock, id, position, vel, acc = P3.P3(0, 0, 0)): + 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.acc = acc # Float holding the acceleration + self.behavior = behavior # Float holding the acceleration self.flock = flock # Current flock holding boid object def move_Boid(self, tick): # Called to change the velocity and position of a particuliar boid - self.vel = self.vel + self.acc * tick # Update velocity by adding the acceleration and multiplying by the tick + 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 diff --git a/src/Flock.py b/src/Flock.py index 3360365..8754f22 100644 --- a/src/Flock.py +++ b/src/Flock.py @@ -2,6 +2,7 @@ import P3 import math import random +import Behavior class Flock: @@ -18,11 +19,11 @@ 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) - self.boids.append(Boid.Boid(self, i, P3.P3(x, y, 50) + center, P3.P3(-5, 0, 0), P3.P3(0, 0, 0))) + self.boids.append(Boid.Boid(self, i, P3.P3(x, y, 50) + center, P3.P3(5, 0, 0), Behavior.behavior)) def update(self, tick): for b in self.boids: - b.move_Boid(self.distance_matrix, tick) + b.move_Boid(tick) self.update_dist_matrix() def update_dist_matrix(self): diff --git a/src/P3.py b/src/P3.py index d59e9d8..6d7844b 100644 --- a/src/P3.py +++ b/src/P3.py @@ -20,13 +20,16 @@ def __add__(self, other): return P3(self.x+other.x, self.y+other.y, self.z+other.z) def distance(self, other=None): - other = other if not None else P3(0, 0, 0) + other = other if other is not None else P3(0, 0, 0) return math.sqrt((self.x+other.x)**2 + (self.y+other.y)**2 + (self.z+other.z)**2) def normalize(self): - magnitude = self.distance() + 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) + ')' @@ -41,3 +44,4 @@ def __str__(self): print(p1 * 2) print(p1 * p2) + print(P3.normalize(p2)) diff --git a/src/render.py b/src/render.py index 1b025dc..881d36b 100644 --- a/src/render.py +++ b/src/render.py @@ -7,6 +7,7 @@ import random import Flock import Boid +import P3 x = 800 y = 600 @@ -250,12 +251,21 @@ def draw(): if __name__ == "__main__": #for num in range(100): #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) - flock = Flock.Flock(100, 0, 0) + flock = Flock.Flock(100, P3.P3(-20, 0, 0), 20) # for b in flock.boids: start(800, 600, 1000) - for i in range(100): + for num in range(10): + color = (random.randrange(0, 2), random.randrange(0, 2), random.randrange(0, 2)) + color_list.append(color) + + for num in range(10): + set_building(random.randrange(-10,10), random.randrange(-10,10), 0,random.randrange(2,20) , random.randrange(2,20), random.randrange(2,20)) + + while 1: draw() + for b in flock.boids: + b.move_Boid(.1) #make_bird_vertices(flock.boids[i]) #bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) @@ -264,15 +274,7 @@ def draw(): # bird_velocity(random.randrange(-5, 5), random.randrange(-5, 5), random.randrange(-5, 5), num) - for num in range(10): - color = (random.randrange(0, 2), random.randrange(0, 2), random.randrange(0, 2)) - color_list.append(color) - - for num in range(10): - set_building(random.randrange(-10,10), random.randrange(-10,10), 0,random.randrange(2,20) , random.randrange(2,20), random.randrange(2,20)) - while True: - draw() From 54b31f3b3548563310bba1a6e6aecaf80e2a91a1 Mon Sep 17 00:00:00 2001 From: micascheid Date: Wed, 4 Oct 2017 11:50:14 -0600 Subject: [PATCH 07/18] __init__ dawwwwwwwwwg --- src/render.py | 219 +++++++++++++++++++++++++++----------------------- 1 file changed, 118 insertions(+), 101 deletions(-) diff --git a/src/render.py b/src/render.py index 881d36b..26e2cbf 100644 --- a/src/render.py +++ b/src/render.py @@ -22,12 +22,12 @@ boid_dict = {} bird_vertices = ( - (0, 0, 0), - (0, 1, .25), - (-1, 1, 0), - (0, 1, -.25), - (1, 1, 0) - ) + (0, 0, 0), + (0, 1, .25), + (-1, 1, 0), + (0, 1, -.25), + (1, 1, 0) + ) ground_vertices = ( (-100, 100, -.1), (100, 100, -.1), @@ -52,28 +52,76 @@ ) -#draws the ground (render use only) +# draws the ground (render use only) def ground(): glBegin(GL_QUADS) for edges in ground_edges: for vert in edges: - glColor3fv((0,.5,.5)) + glColor3fv((0, .5, .5)) glVertex3fv(ground_vertices[vert]) glEnd() -#moves bird according to velocity (render use only) -def update_birds(birdNum): - thisVelocity = bird_velocity_dict[birdNum] - thisBird = bird_dict[birdNum] - #print(thisBird) - #changes the position of the birds vertices - for vert in thisBird: - vert[0] = vert[0] + thisVelocity[0] #x value - vert[1] = vert[1] + thisVelocity[1] #y value - vert[2] = vert[2] + thisVelocity[2] #z value +def set_building(bx, by, bz, width, height, depth): + new_vertices = [] + final_vertices = [] + global building_count + + #positoning + for vert in building_vertices: + new_vert = [] + + new_x = vert[0] + bx + new_y = vert[1] + by + new_z = vert[2] + bz + + 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: + fnew_vert = [] + + newv_x = nvert[0] * width + newv_y = nvert[1] * depth + newv_z = nvert[2] * height + + fnew_vert.append(newv_x) + fnew_vert.append(newv_y) + fnew_vert.append(newv_z) + + final_vertices.append(fnew_vert) + + building_dict[building_count] = final_vertices + building_count += 1 + color_list.append(color) + + +def make_bird_vertices(bird): + new_vertices = [] + global bird_count + + for vert in bird_vertices: + new_vert = [] + + new_x = vert[0] + bird.position.x + new_y = vert[1] + bird.position.y + new_z = vert[2] + bird.position.z + + new_vert.append(new_x) + new_vert.append(new_y) + new_vert.append(new_z) + + # new_vertices.append(new_vert) + new_vertices.append(new_vert) + + # bird_dict[bird_count] = new_vertices + # bird_count += 1 + return new_vertices - bird_dict[birdNum] = thisBird #used to display birds (render use only) @@ -96,8 +144,7 @@ def draw_bird(vertices): glEnd() -#sets bird velocity (call to set and change velocity) -#birdNum = 0 -> (# of birds added - 1) + def bird_velocity(x_velocity, y_velocity, z_velocity, birdNum): bird_velocity_dict[birdNum] = [x_velocity, y_velocity, z_velocity] @@ -140,108 +187,77 @@ def building(vertices, color): glEnd() -def set_building(bx, by, bz, width, height, depth): - new_vertices = [] - final_vertices = [] - global building_count - #positoning - for vert in building_vertices: - new_vert = [] - - new_x = vert[0] + bx - new_y = vert[1] + by - new_z = vert[2] + bz - - new_vert.append(new_x) - new_vert.append(new_y) - new_vert.append(new_z) +def start(width, hieght, depth): + pygame.init() + display = (width, hieght) + pygame.display.set_mode(display, DOUBLEBUF | OPENGL) - new_vertices.append(new_vert) + gluPerspective(45, (display[0]/display[1]), 0.1, depth) + glTranslatef(-10, 30, -250) + glRotatef(-45, 1, 1, 1) - #scaling - for nvert in new_vertices: - fnew_vert = [] - newv_x = nvert[0] * width - newv_y = nvert[1] * depth - newv_z = nvert[2] * height +class Render: + def __init__(self, flock): + self.flock = flock - fnew_vert.append(newv_x) - fnew_vert.append(newv_y) - fnew_vert.append(newv_z) - final_vertices.append(fnew_vert) - building_dict[building_count] = final_vertices - building_count += 1 - color_list.append(color) - - -#initializes birds at a given x, y, z (call add a bird) -def make_bird_vertices(bird): - new_vertices = [] - global bird_count - - for vert in bird_vertices: - new_vert = [] + #moves bird according to velocity (render use only) + # def update_birds(birdNum): + # thisVelocity = bird_velocity_dict[birdNum] + # thisBird = bird_dict[birdNum] + # #print(thisBird) + # #changes the position of the birds vertices + # for vert in thisBird: + # vert[0] = vert[0] + thisVelocity[0] #x value + # vert[1] = vert[1] + thisVelocity[1] #y value + # vert[2] = vert[2] + thisVelocity[2] #z value + # + # bird_dict[birdNum] = thisBird - new_x = vert[0] + bird.position.x - new_y = vert[1] + bird.position.y - new_z = vert[2] + bird.position.z - new_vert.append(new_x) - new_vert.append(new_y) - new_vert.append(new_z) + #sets bird velocity (call to set and change velocity) + #birdNum = 0 -> (# of birds added - 1) - # new_vertices.append(new_vert) - new_vertices.append(new_vert) + #initializes birds at a given x, y, z (call add a bird) - #bird_dict[bird_count] = new_vertices - #bird_count += 1 - return new_vertices -#initiates display window (call one time to start display) -def start(width, hieght, depth): - pygame.init() - display = (width, hieght) - pygame.display.set_mode(display, DOUBLEBUF | OPENGL) + #initiates display window (call one time to start display) - gluPerspective(45, (display[0]/display[1]), 0.1, depth) - glTranslatef(-10, 30, -250) - glRotatef(-45, 1, 1, 1) -#draws objects on screen (call each tick of the clock) -def draw(): - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - sys.exit() + #draws objects on screen (call each tick of the clock) + def draw(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - ground() + ground() - # for each_bird in bird_velocity_dict: - # update_birds(each_bird) - # - # for each_bird in bird_dict: - # bird(bird_dict[each_bird]) - # - for each_building in building_dict: - building(building_dict[each_building], color_list[each_building]) + # for each_bird in bird_velocity_dict: + # update_birds(each_bird) + # + # for each_bird in bird_dict: + # bird(bird_dict[each_bird]) + # + for each_building in building_dict: + building(building_dict[each_building], color_list[each_building]) - for b in flock.boids: - v = make_bird_vertices(b) - draw_bird(v) + for b in self.flock.boids: + v = make_bird_vertices(b) + draw_bird(v) - pygame.display.flip() + pygame.display.flip() @@ -252,6 +268,8 @@ def draw(): #for num in range(100): #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) flock = Flock.Flock(100, P3.P3(-20, 0, 0), 20) + f = Render(flock) + # for b in flock.boids: start(800, 600, 1000) @@ -263,11 +281,10 @@ def draw(): set_building(random.randrange(-10,10), random.randrange(-10,10), 0,random.randrange(2,20) , random.randrange(2,20), random.randrange(2,20)) while 1: - draw() + f.draw() for b in flock.boids: b.move_Boid(.1) - #make_bird_vertices(flock.boids[i]) - #bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) + # for num in range(100): From a130487d5c4f6ae11c9431be2b4c3b96f393739c Mon Sep 17 00:00:00 2001 From: shane-m-calhoun Date: Wed, 4 Oct 2017 19:04:04 -0600 Subject: [PATCH 08/18] Add files via upload --- src/render.py | 219 +++++++++++++++++++++++--------------------------- 1 file changed, 101 insertions(+), 118 deletions(-) diff --git a/src/render.py b/src/render.py index 26e2cbf..881d36b 100644 --- a/src/render.py +++ b/src/render.py @@ -22,12 +22,12 @@ boid_dict = {} bird_vertices = ( - (0, 0, 0), - (0, 1, .25), - (-1, 1, 0), - (0, 1, -.25), - (1, 1, 0) - ) + (0, 0, 0), + (0, 1, .25), + (-1, 1, 0), + (0, 1, -.25), + (1, 1, 0) + ) ground_vertices = ( (-100, 100, -.1), (100, 100, -.1), @@ -52,76 +52,28 @@ ) -# draws the ground (render use only) +#draws the ground (render use only) def ground(): glBegin(GL_QUADS) for edges in ground_edges: for vert in edges: - glColor3fv((0, .5, .5)) + glColor3fv((0,.5,.5)) glVertex3fv(ground_vertices[vert]) glEnd() -def set_building(bx, by, bz, width, height, depth): - new_vertices = [] - final_vertices = [] - global building_count - - #positoning - for vert in building_vertices: - new_vert = [] - - new_x = vert[0] + bx - new_y = vert[1] + by - new_z = vert[2] + bz - - 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: - fnew_vert = [] - - newv_x = nvert[0] * width - newv_y = nvert[1] * depth - newv_z = nvert[2] * height - - fnew_vert.append(newv_x) - fnew_vert.append(newv_y) - fnew_vert.append(newv_z) - - final_vertices.append(fnew_vert) - - building_dict[building_count] = final_vertices - building_count += 1 - color_list.append(color) - - -def make_bird_vertices(bird): - new_vertices = [] - global bird_count - - for vert in bird_vertices: - new_vert = [] - - new_x = vert[0] + bird.position.x - new_y = vert[1] + bird.position.y - new_z = vert[2] + bird.position.z - - new_vert.append(new_x) - new_vert.append(new_y) - new_vert.append(new_z) - - # new_vertices.append(new_vert) - new_vertices.append(new_vert) - - # bird_dict[bird_count] = new_vertices - # bird_count += 1 - return new_vertices +#moves bird according to velocity (render use only) +def update_birds(birdNum): + thisVelocity = bird_velocity_dict[birdNum] + thisBird = bird_dict[birdNum] + #print(thisBird) + #changes the position of the birds vertices + for vert in thisBird: + vert[0] = vert[0] + thisVelocity[0] #x value + vert[1] = vert[1] + thisVelocity[1] #y value + vert[2] = vert[2] + thisVelocity[2] #z value + bird_dict[birdNum] = thisBird #used to display birds (render use only) @@ -144,7 +96,8 @@ def draw_bird(vertices): glEnd() - +#sets bird velocity (call to set and change velocity) +#birdNum = 0 -> (# of birds added - 1) def bird_velocity(x_velocity, y_velocity, z_velocity, birdNum): bird_velocity_dict[birdNum] = [x_velocity, y_velocity, z_velocity] @@ -187,77 +140,108 @@ def building(vertices, color): glEnd() +def set_building(bx, by, bz, width, height, depth): + new_vertices = [] + final_vertices = [] + global building_count -def start(width, hieght, depth): - pygame.init() - display = (width, hieght) - pygame.display.set_mode(display, DOUBLEBUF | OPENGL) + #positoning + for vert in building_vertices: + new_vert = [] - gluPerspective(45, (display[0]/display[1]), 0.1, depth) - glTranslatef(-10, 30, -250) - glRotatef(-45, 1, 1, 1) + new_x = vert[0] + bx + new_y = vert[1] + by + new_z = vert[2] + bz + new_vert.append(new_x) + new_vert.append(new_y) + new_vert.append(new_z) -class Render: - def __init__(self, flock): - self.flock = flock + new_vertices.append(new_vert) + #scaling + for nvert in new_vertices: + fnew_vert = [] + newv_x = nvert[0] * width + newv_y = nvert[1] * depth + newv_z = nvert[2] * height - #moves bird according to velocity (render use only) - # def update_birds(birdNum): - # thisVelocity = bird_velocity_dict[birdNum] - # thisBird = bird_dict[birdNum] - # #print(thisBird) - # #changes the position of the birds vertices - # for vert in thisBird: - # vert[0] = vert[0] + thisVelocity[0] #x value - # vert[1] = vert[1] + thisVelocity[1] #y value - # vert[2] = vert[2] + thisVelocity[2] #z value - # - # bird_dict[birdNum] = thisBird + fnew_vert.append(newv_x) + fnew_vert.append(newv_y) + fnew_vert.append(newv_z) + final_vertices.append(fnew_vert) - #sets bird velocity (call to set and change velocity) - #birdNum = 0 -> (# of birds added - 1) + building_dict[building_count] = final_vertices + building_count += 1 + color_list.append(color) - #initializes birds at a given x, y, z (call add a bird) +#initializes birds at a given x, y, z (call add a bird) +def make_bird_vertices(bird): + new_vertices = [] + global bird_count + + for vert in bird_vertices: + new_vert = [] + + new_x = vert[0] + bird.position.x + new_y = vert[1] + bird.position.y + new_z = vert[2] + bird.position.z + + new_vert.append(new_x) + new_vert.append(new_y) + new_vert.append(new_z) + + # new_vertices.append(new_vert) + new_vertices.append(new_vert) + #bird_dict[bird_count] = new_vertices + #bird_count += 1 + return new_vertices - #initiates display window (call one time to start display) +#initiates display window (call one time to start display) +def start(width, hieght, depth): + pygame.init() + display = (width, hieght) + pygame.display.set_mode(display, DOUBLEBUF | OPENGL) + gluPerspective(45, (display[0]/display[1]), 0.1, depth) + glTranslatef(-10, 30, -250) + glRotatef(-45, 1, 1, 1) - #draws objects on screen (call each tick of the clock) - def draw(self): - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - sys.exit() - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) +#draws objects on screen (call each tick of the clock) +def draw(): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - ground() - # for each_bird in bird_velocity_dict: - # update_birds(each_bird) - # - # for each_bird in bird_dict: - # bird(bird_dict[each_bird]) - # - for each_building in building_dict: - building(building_dict[each_building], color_list[each_building]) + ground() - for b in self.flock.boids: - v = make_bird_vertices(b) - draw_bird(v) + # for each_bird in bird_velocity_dict: + # update_birds(each_bird) + # + # for each_bird in bird_dict: + # bird(bird_dict[each_bird]) + # + for each_building in building_dict: + building(building_dict[each_building], color_list[each_building]) + for b in flock.boids: + v = make_bird_vertices(b) + draw_bird(v) - pygame.display.flip() + + pygame.display.flip() @@ -268,8 +252,6 @@ def draw(self): #for num in range(100): #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) flock = Flock.Flock(100, P3.P3(-20, 0, 0), 20) - f = Render(flock) - # for b in flock.boids: start(800, 600, 1000) @@ -281,10 +263,11 @@ def draw(self): set_building(random.randrange(-10,10), random.randrange(-10,10), 0,random.randrange(2,20) , random.randrange(2,20), random.randrange(2,20)) while 1: - f.draw() + draw() for b in flock.boids: b.move_Boid(.1) - + #make_bird_vertices(flock.boids[i]) + #bird_velocity(flock.boids[i].vel.x, flock.boids[i].vel.y, flock.boids[i].vel.z, i) # for num in range(100): From e0688898c8f48ca51caa056c55088329b3bc03c2 Mon Sep 17 00:00:00 2001 From: shane-m-calhoun Date: Wed, 4 Oct 2017 19:04:58 -0600 Subject: [PATCH 09/18] Add files via upload From 4c14137fe6a3afc92d029b76d3f7b8e927c0fe80 Mon Sep 17 00:00:00 2001 From: micascheid Date: Wed, 4 Oct 2017 19:09:02 -0600 Subject: [PATCH 10/18] Building stuff --- src/render.py | 219 ++++++++++++++++++++++---------------------------- 1 file changed, 96 insertions(+), 123 deletions(-) diff --git a/src/render.py b/src/render.py index 26e2cbf..1eb11d0 100644 --- a/src/render.py +++ b/src/render.py @@ -51,6 +51,16 @@ (0,1,-1)#7 ) +#call to create display +def start(width, hieght, depth): + pygame.init() + display = (width, hieght) + pygame.display.set_mode(display, DOUBLEBUF | OPENGL) + + gluPerspective(45, (display[0]/display[1]), 0.1, depth) + glTranslatef(-10, 30, -250) + glRotatef(-45, 1, 1, 1) + # draws the ground (render use only) def ground(): @@ -62,44 +72,9 @@ def ground(): glEnd() -def set_building(bx, by, bz, width, height, depth): - new_vertices = [] - final_vertices = [] - global building_count - - #positoning - for vert in building_vertices: - new_vert = [] - - new_x = vert[0] + bx - new_y = vert[1] + by - new_z = vert[2] + bz - - 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: - fnew_vert = [] - - newv_x = nvert[0] * width - newv_y = nvert[1] * depth - newv_z = nvert[2] * height - - fnew_vert.append(newv_x) - fnew_vert.append(newv_y) - fnew_vert.append(newv_z) - - final_vertices.append(fnew_vert) - - building_dict[building_count] = final_vertices - building_count += 1 - color_list.append(color) +#creates vertices for individual birds (render use only) def make_bird_vertices(bird): new_vertices = [] global bird_count @@ -144,41 +119,6 @@ def draw_bird(vertices): glEnd() - -def bird_velocity(x_velocity, y_velocity, z_velocity, birdNum): - bird_velocity_dict[birdNum] = [x_velocity, y_velocity, z_velocity] - -def building(vertices, color): - edges = ( - (0, 1), - (0, 4), - (1, 2), - (1, 5), - (2, 3), - (2, 6), - (3, 0), - (3, 7), - (4, 5), - (5, 6), - (6, 7), - (7, 4) - ) - surfaces = ( - (0,1,2,3), - (2,6,5,1), - (0,1,4,5), - (0,3,7,4), - (3,7,6,2), - (7,4,5,6) - ) - glBegin(GL_QUADS) - for surface in surfaces: - for vertex in surface: - glColor3fv(color) - glVertex3fv(vertices[vertex]) - glEnd() - - glBegin(GL_LINES) for edge in edges: for vertex in edge: @@ -187,48 +127,99 @@ def building(vertices, color): glEnd() +#call to create a new building +class Buildings(object): + _registry = [] -def start(width, hieght, depth): - pygame.init() - display = (width, hieght) - pygame.display.set_mode(display, DOUBLEBUF | OPENGL) - - gluPerspective(45, (display[0]/display[1]), 0.1, depth) - glTranslatef(-10, 30, -250) - glRotatef(-45, 1, 1, 1) - - -class Render: - def __init__(self, flock): - self.flock = flock - + def __init__(self, x, y, width, height, depth, color): + self._registry.append(self) + self.x = x + self.y = y + self.width = width + self.height = height + self.depth = depth + self.color = color + #sets building verts (render use only) + def set_building(self): + new_vertices = [] + final_vertices = [] + global building_count - #moves bird according to velocity (render use only) - # def update_birds(birdNum): - # thisVelocity = bird_velocity_dict[birdNum] - # thisBird = bird_dict[birdNum] - # #print(thisBird) - # #changes the position of the birds vertices - # for vert in thisBird: - # vert[0] = vert[0] + thisVelocity[0] #x value - # vert[1] = vert[1] + thisVelocity[1] #y value - # vert[2] = vert[2] + thisVelocity[2] #z value - # - # bird_dict[birdNum] = thisBird + #positoning + for vert in building_vertices: + new_vert = [] + new_x = vert[0] + self.x + new_y = vert[1] + self.y + new_z = vert[2] - #sets bird velocity (call to set and change velocity) - #birdNum = 0 -> (# of birds added - 1) + new_vert.append(new_x) + new_vert.append(new_y) + new_vert.append(new_z) + new_vertices.append(new_vert) - #initializes birds at a given x, y, z (call add a bird) + #scaling + for nvert in new_vertices: + fnew_vert = [] + newv_x = nvert[0] * self.width + newv_y = nvert[1] * self.depth + newv_z = nvert[2] * self.height + fnew_vert.append(newv_x) + fnew_vert.append(newv_y) + fnew_vert.append(newv_z) - #initiates display window (call one time to start display) + final_vertices.append(fnew_vert) + return final_vertices + #displays buildings (render use only) + def draw_building(self): + edges = ( + (0, 1), + (0, 4), + (1, 2), + (1, 5), + (2, 3), + (2, 6), + (3, 0), + (3, 7), + (4, 5), + (5, 6), + (6, 7), + (7, 4) + ) + surfaces = ( + (0,1,2,3), + (2,6,5,1), + (0,1,4,5), + (0,3,7,4), + (3,7,6,2), + (7,4,5,6) + ) + vertices = Buildings.set_building(self) + glBegin(GL_QUADS) + for surface in surfaces: + for vertex in surface: + glColor3fv(self.color) + glVertex3fv(vertices[vertex]) + glEnd() + + + glBegin(GL_LINES) + for edge in edges: + for vertex in edge: + glColor3fv((1, 1, 1)) + glVertex3fv(vertices[vertex]) + glEnd() + +#call to create new flock +class Render: + def __init__(self, flock): + self.flock = flock #draws objects on screen (call each tick of the clock) def draw(self): @@ -239,17 +230,10 @@ def draw(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - ground() - # for each_bird in bird_velocity_dict: - # update_birds(each_bird) - # - # for each_bird in bird_dict: - # bird(bird_dict[each_bird]) - # - for each_building in building_dict: - building(building_dict[each_building], color_list[each_building]) + for building in Buildings._registry: + Buildings.draw_building(building) for b in self.flock.boids: v = make_bird_vertices(b) @@ -270,15 +254,11 @@ def draw(self): flock = Flock.Flock(100, P3.P3(-20, 0, 0), 20) 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))) # for b in flock.boids: start(800, 600, 1000) - for num in range(10): - color = (random.randrange(0, 2), random.randrange(0, 2), random.randrange(0, 2)) - color_list.append(color) - - for num in range(10): - set_building(random.randrange(-10,10), random.randrange(-10,10), 0,random.randrange(2,20) , random.randrange(2,20), random.randrange(2,20)) while 1: f.draw() @@ -286,12 +266,5 @@ def draw(self): b.move_Boid(.1) - # for num in range(100): # bird_velocity(random.randrange(-5, 5), random.randrange(-5, 5), random.randrange(-5, 5), num) - - - - - - From 9fc674e9777b16abe6f984806d1fb3e69cf46dca Mon Sep 17 00:00:00 2001 From: micascheid Date: Wed, 4 Oct 2017 19:13:50 -0600 Subject: [PATCH 11/18] Building class --- src/render.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/render.py b/src/render.py index 1eb11d0..8e3bc46 100644 --- a/src/render.py +++ b/src/render.py @@ -256,7 +256,7 @@ def draw(self): 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))) - # for b in flock.boids: + start(800, 600, 1000) @@ -265,6 +265,3 @@ def draw(self): for b in flock.boids: b.move_Boid(.1) - - # for num in range(100): - # bird_velocity(random.randrange(-5, 5), random.randrange(-5, 5), random.randrange(-5, 5), num) From 0d988fad916fc79084261bd90f61daa40116c8e5 Mon Sep 17 00:00:00 2001 From: shane-m-calhoun Date: Wed, 4 Oct 2017 19:38:30 -0600 Subject: [PATCH 12/18] Add files via upload --- src/render.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/render.py b/src/render.py index 8e3bc46..23083f7 100644 --- a/src/render.py +++ b/src/render.py @@ -13,13 +13,7 @@ y = 600 z = 1000 -bird_count = 0 -bird_dict = {} -bird_velocity_dict = {} -building_dict = {} -building_count = 0 -color_list = [] -boid_dict = {} + bird_vertices = ( (0, 0, 0), @@ -72,12 +66,9 @@ def ground(): glEnd() - - #creates vertices for individual birds (render use only) def make_bird_vertices(bird): new_vertices = [] - global bird_count for vert in bird_vertices: new_vert = [] @@ -90,11 +81,8 @@ def make_bird_vertices(bird): new_vert.append(new_y) new_vert.append(new_z) - # new_vertices.append(new_vert) new_vertices.append(new_vert) - # bird_dict[bird_count] = new_vertices - # bird_count += 1 return new_vertices @@ -249,14 +237,12 @@ def draw(self): if __name__ == "__main__": - #for num in range(100): - #set_bird_vertices(random.randrange(-20, 20), random.randrange(0, 20), random.randrange(-100, 0)) flock = Flock.Flock(100, P3.P3(-20, 0, 0), 20) 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))) - + start(800, 600, 1000) From fa5f0ff9fe96db91c152dee83da7b00feaa17bb6 Mon Sep 17 00:00:00 2001 From: micascheid Date: Fri, 6 Oct 2017 11:00:55 -0600 Subject: [PATCH 13/18] Update to initial flock positioning --- src/render.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render.py b/src/render.py index 23083f7..2a70025 100644 --- a/src/render.py +++ b/src/render.py @@ -237,7 +237,7 @@ def draw(self): if __name__ == "__main__": - flock = Flock.Flock(100, P3.P3(-20, 0, 0), 20) + flock = Flock.Flock(20, P3.P3(-75, -75, 0), 10) f = Render(flock) for num in range(10): From 113ab1203597a6c5b458d44cfcda1116c711f2e9 Mon Sep 17 00:00:00 2001 From: micascheid Date: Fri, 6 Oct 2017 11:39:53 -0600 Subject: [PATCH 14/18] Start Class --- .gitignore | 12 ++ .idea/boids.iml | 2 +- .idea/misc.xml | 2 +- .idea/workspace.xml | 357 ++++++++++++++++++++++++++++++++++++++------ src/Behavior.py | 41 ++++- src/Boid.py | 15 ++ src/Config.py | 48 ++++++ src/Flock.py | 18 ++- src/Gui.py | 113 +++++++------- src/GuiTest.py | 25 ++++ src/Main.py | 23 ++- src/P3.py | 11 ++ 12 files changed, 547 insertions(+), 120 deletions(-) create mode 100644 src/Config.py create mode 100644 src/GuiTest.py diff --git a/.gitignore b/.gitignore index 6355656..be8a63b 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,9 @@ instance/ # Sphinx documentation docs/_build/ +#pycharm +.idea/ + # PyBuilder target/ @@ -99,9 +102,18 @@ ENV/ # mypy .mypy_cache/ +<<<<<<< HEAD src/Render.py src/render.py src/render.py +======= +.vscode/ +.idea/boids.iml +.idea/boids.iml +.idea/misc.xml +*.iml +.idea/workspace.xml +>>>>>>> master diff --git a/.idea/boids.iml b/.idea/boids.iml index 6711606..1e7d6ae 100644 --- a/.idea/boids.iml +++ b/.idea/boids.iml @@ -2,7 +2,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 3a3f450..1fb1569 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c18186f..08bfdd2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,10 @@ - - + + + + + + + + - - - - - - - - - - - - + + - - + + - - + + - - - + + + + + - - + + - - + + @@ -56,6 +54,18 @@ + + + + + + void + + - + + + + + + + + + + + + + + + + + + + + + + + 1506705703762 - - + + - + - - + + - + @@ -178,10 +272,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -240,7 +451,6 @@ - @@ -248,7 +458,6 @@ - @@ -264,22 +473,78 @@ - - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Behavior.py b/src/Behavior.py index 9afcfec..c057bcb 100644 --- a/src/Behavior.py +++ b/src/Behavior.py @@ -2,6 +2,7 @@ def behavior(boid): +<<<<<<< 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] < @@ -14,21 +15,59 @@ def behavior(boid): v1 = P3.P3(0, 0, 0) for other in avoid: v1 += other.position.vectorTo(boid.position) * (1 / boid.position.distance(other.position)) +======= + max_acc = .1 + max_vel = 25 + r = 200 + 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 + r2 = 50 + avoid = [other for other in nby if boid.id > other.id and boid.flock.distance_matrix[boid.id][other.id] < r2 + or other.id > boid.id and boid.flock.distance_matrix[other.id][boid.id] < r2] + v1 = P3.P3(0, 0, 0) + for other in avoid: + v1 += other.position - boid.position * (1 / boid.position.distance(other.position)**2) +>>>>>>> master # velocity matching v2 = P3.P3(0, 0, 0) for b in nby: +<<<<<<< HEAD v2 += b.vel if len(nby) > 1: v2 *= 1/len(nby) +======= + v2 += b.velocity + if len(nby) > 1: + v2 *= 1/len(nby) + v2 -= boid.velocity +>>>>>>> master # flock centering v3 = P3.P3(0, 0, 0) for b in nby: v3 += b.position if len(nby) > 1: +<<<<<<< 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) \ No newline at end of file + return P3.P3.normalize(delta_vel) +======= + v3 *= 1 / len(nby) + v3 -= boid.position + + # Robin: Cod = .35, mass = 0.0182kg, density = 1.09kg/m^3, body frontal area = 4.6cm^2 + # c = coefficient of drag * density * perpendicular area * 1/2 + c = .0088 * 1 + drag = c * boid.velocity.distance()**2 + drag_vector = -1 * boid.velocity * drag + + delta_vel = 50*v1 + 800*v2 + 5000*v3 # - drag_vector + + acc = P3.P3.normalize(delta_vel) * max_acc + + return acc if acc.distance() < delta_vel.distance() else delta_vel +>>>>>>> master diff --git a/src/Boid.py b/src/Boid.py index 8393f1d..1dfa087 100644 --- a/src/Boid.py +++ b/src/Boid.py @@ -3,17 +3,32 @@ class Boid: +<<<<<<< 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 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 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 diff --git a/src/Config.py b/src/Config.py new file mode 100644 index 0000000..9f364b2 --- /dev/null +++ b/src/Config.py @@ -0,0 +1,48 @@ + +class Config: + + def __init__(self): + return True + + +class Config_World: + + def __init__(self,screen, objects,flocks): + #init + return True + +class Config_Screen: + def __init__(self, x_pos, y_pos, x_size, y_size): + return True + +class Config_Static_Object: + + def __init__(self): + return True + +class Config_Flock: + + def __init__(self,boids = None,center = None, radius = None): + self.boids = boids + self.center = center + self.radius = radius + +class Config_Boid: + + behaviors = () + + def __init__(self, parent, id, velocity_max, velocity, position, behavior): + self.parent = parent + self.id = id + self.velocity=velocity + self.position = position + self.velocity_max=velocity_max + self.behavior = behavior + +class Config_Behavior: + + def __init__(self, id, neighbor = 0, center = 0, direction = 0): + self.id + self.neighbor_weight = neighbor + self.center_weight = center + self.direction_weight = direction \ No newline at end of file diff --git a/src/Flock.py b/src/Flock.py index 8754f22..a83ae42 100644 --- a/src/Flock.py +++ b/src/Flock.py @@ -1,3 +1,4 @@ +import Behavior import Boid import P3 import math @@ -7,7 +8,7 @@ class Flock: flock_count = 0 - + def __init__(self, num_boids, center=P3.P3(0, 0, 0), radius=20): #possibly also orientation, maybe something about obstacles? Flock.flock_count += 1 self.boids = [] @@ -19,7 +20,15 @@ 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 self.boids.append(Boid.Boid(self, i, P3.P3(x, y, 50) + center, P3.P3(5, 0, 0), Behavior.behavior)) +======= + # 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() +>>>>>>> master def update(self, tick): for b in self.boids: @@ -33,6 +42,7 @@ def update_dist_matrix(self): if __name__ == '__main__': - flock = Flock(10, P3.P3(100, 100, 1), 1) - for b in flock.boids: - print(b.position) \ No newline at end of file + flock = Flock(20, P3.P3(-200, -100, 50), 20) + for i in range(20): + flock.update(1) + print() diff --git a/src/Gui.py b/src/Gui.py index e7eba32..a2a8ae2 100644 --- a/src/Gui.py +++ b/src/Gui.py @@ -1,39 +1,7 @@ import tkinter as tk -class Config: - def __init__(self): - self.size=(0,0) - self.flocks=0 - self.boids=0 - self.initial_flock_placement=(0,0) - self.boid_behavior = Boid_Behavior() - - def get_size(self): - return self.size - def set_size(self,size): - self.size=(float(size[0]),float(size[1])) - - def get_flocks(self): - return self.flocks - def set_flocks(self,count): - self.flocks=int(count) - - def get_boids(self): - return self.boids - def set_boids(self,count): - self.boids=count - - def get_initial_flock_placement(self): - return self.initial_flock_placement - def set_initial_flock_placement(self,position): - self.initial_flock_placement=(float(position[0]),float(position[1])) - - def get_boid_behavior(self): - return self.boid_behavior - def set_boid_behavior(self,perception,distance,decay): - self.boid_behavior=Boid_Behavior(perception=0,distance=0,decay=0) class Boid_Behavior: @@ -44,10 +12,32 @@ def __init__(self,perception=0,distance=0,decay=0): self.decay_weight=decay class GUI(tk.Frame): - def __init__(self,master): - tk.Frame.__init__(self,master) - self.master=master - self.default_height=120 + + def get_master(self): + return self.master + + def start(self, tick_method=None, tick_wait=500): + if not self.__is_started: + self.__is_started = True + self.tick_method = tick_method + self.tick_wait = tick_wait + if self.tick_method != None: + self.master.after(self.tick_wait, self.tick) + self.master.mainloop() + + def tick(self): + self.tick_method() + self.master.after(self.tick_wait, self.tick) + + def __init__(self): + self.__is_started = False + self.master = tk.Tk() + self.master.resizable(0, 0) + self.default_height = 120 + self.tick_method = None + self.tick_wait = None + + tk.Frame.__init__(self, self.master) self.config = Config() self.init_ui() @@ -56,7 +46,7 @@ def init_ui(self): self.init_controls() def init_position(self): - self.master.title("Python Boids"); + self.master.title("Python Boids") self.pack(fill=tk.BOTH, expand=True) self.app_window = tk.Toplevel(self.master) self.app_frame = tk.Frame(self.app_window) @@ -68,7 +58,7 @@ def init_position(self): self.ui_x = -7 self.ui_y = 0 - self.config.set_size((sw,sh-self.default_height)) + self.config.set_size((sw, sh-self.default_height)) self.master.geometry('%dx%d+%d+%d' % (sw, self.default_height, self.ui_x, self.ui_y)) @@ -89,26 +79,29 @@ def init_flock_frame(self): frame_flock_list.pack(side=tk.LEFT, anchor=tk.N, padx=5, pady=5) frame_flock_list_1 = tk.Frame(frame_flock_list) - frame_flock_list_1.pack(side=tk.LEFT,padx=1) + frame_flock_list_1.pack(side=tk.LEFT, padx=1) label_flock = tk.Label(frame_flock_list_1, text="Flock") label_flock.pack(side=tk.TOP, padx=5, pady=5) - listbox_flocks_scrollbar = tk.Scrollbar(frame_flock_list_1,orient=tk.VERTICAL) - listbox_flocks = tk.Listbox(frame_flock_list_1,yscrollcommand=listbox_flocks_scrollbar.set,name='listbox_flocks',height=1,width=16) + listbox_flocks_scrollbar = tk.Scrollbar(frame_flock_list_1, orient=tk.VERTICAL) + listbox_flocks = tk.Listbox(\ + frame_flock_list_1,\ + yscrollcommand=listbox_flocks_scrollbar.set,\ + name='listbox_flocks', height=1, width=16) #listbox_flocks_scrollbar.config(command=listbox_flocks_scrollbar.yview) - listbox_flocks_scrollbar.pack(side=tk.RIGHT,fill=tk.Y) + listbox_flocks_scrollbar.pack(side=tk.RIGHT, fill=tk.Y) - listbox_flocks.pack(side=tk.TOP,fill=tk.Y) + listbox_flocks.pack(side=tk.TOP, fill=tk.Y) listbox_flocks.insert(tk.END, "0") listbox_flocks.insert(tk.END, "1") listbox_flocks.bind('<>', GUI.on_select) frame_flock_list_2 = tk.Frame(frame_flock_list) - frame_flock_list_2.pack(side=tk.LEFT,padx=1,fill=tk.BOTH) + frame_flock_list_2.pack(side=tk.LEFT, padx=1, fill=tk.BOTH) - button_remove_flock = tk.Button(frame_flock_list_2,text="Remove Flock") - button_remove_flock.pack(side=tk.BOTTOM,fill=tk.BOTH) + button_remove_flock = tk.Button(frame_flock_list_2, text="Remove Flock") + button_remove_flock.pack(side=tk.BOTTOM, fill=tk.BOTH) button_add_flock = tk.Button(frame_flock_list_2, text="Add Flock") button_add_flock.pack(side=tk.BOTTOM, fill=tk.BOTH) @@ -145,24 +138,20 @@ def init_flock_frame(self): return frame_flock - #def show(self): - # root = tk.Tk() - # root.resizable(0, 0) - - # app = GUI(root) - - # root.mainloop() + def set_visible(self, value): + if isinstance(value, bool): + if value == True: + self.master.update() + self.master.deiconify() + else: + self.master.withdraw() def on_select(evt): - w=evt.widget - index=int(w.curselection()[0]) - value=w.get(index) + w = evt.widget + index = int(w.curselection()[0]) + value = w.get(index) r = value if __name__=='__main__': - root = tk.Tk() - root.resizable(0, 0) - - app = GUI(root) - - root.mainloop() \ No newline at end of file + app = GUI() + app.start() diff --git a/src/GuiTest.py b/src/GuiTest.py new file mode 100644 index 0000000..87a944c --- /dev/null +++ b/src/GuiTest.py @@ -0,0 +1,25 @@ +import src.Gui + +class Application: + + def __init__(self): + self.data=None + self.gui=src.Gui.GUI() + self.is_visible=True + self.data = self.gui.start(self.on_tick,1500) + + def print_console(self): + print("Hello") + + def on_tick(self): + self.print_console() + self.is_visible = not self.is_visible + #self.gui.set_visible(self.is_visible) + +if __name__ == '__main__': + app = Application() + if app.data == None: + print("Hello") + + #gui.set_visible(False) + #gui.set_visible(True) \ No newline at end of file diff --git a/src/Main.py b/src/Main.py index 21aee14..c6e4369 100644 --- a/src/Main.py +++ b/src/Main.py @@ -2,17 +2,30 @@ import WorldObjects from World import World import threading +from src.Flock import Flock +from src.render import Render +import time +import P3 guiX = 40 guiY = 40 z = 40 +c = 0 +r = 0 buildings = {} +tick = 0.05 world = World(guiX,guiY,z,buildings) -f1 = Flock(5, ) -def printit(): #this will be replaced with incremental function calls - threading.Timer(1.0, printit).start() #such as flock and boid directional and velocity changes - print (world.timer.get_time_s()) #instead of displaying time every second +F1 = Flock(100, P3.P3(-20, 0, 0), 20) +F1_r = Render(F1) + +for i in range(7000): + print(tick) + F1_r.draw() + time.sleep(tick) + + +#can change to pass update and tick to render +# F1.update(0.05) -printit() \ No newline at end of file diff --git a/src/P3.py b/src/P3.py index 6d7844b..e836a82 100644 --- a/src/P3.py +++ b/src/P3.py @@ -19,6 +19,9 @@ def __mul__(self, other): def __add__(self, other): return P3(self.x+other.x, self.y+other.y, self.z+other.z) + def __sub__(self, other): + return P3(self.x - other.x, self.y - other.y, self.z - other.z) + def distance(self, other=None): other = other if other is not None else P3(0, 0, 0) return math.sqrt((self.x+other.x)**2 + (self.y+other.y)**2 + (self.z+other.z)**2) @@ -43,5 +46,13 @@ def __str__(self): print(2 * p1) print(p1 * 2) print(p1 * p2) + print(P3.normalize(p1)) + print(1.123 * p1) + + print() + print(p2 - p1) + p3 = P3(-100, 100, -100) + print(p3 - p1) + print(P3.normalize(p2)) From 4211695db80cc7bee67999f248b41cd2d06020d1 Mon Sep 17 00:00:00 2001 From: Dalton Welch Date: Mon, 9 Oct 2017 11:42:15 -0600 Subject: [PATCH 15/18] Add files via upload --- src/render.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/render.py b/src/render.py index 2a70025..a51b5cc 100644 --- a/src/render.py +++ b/src/render.py @@ -117,10 +117,10 @@ def draw_bird(vertices): #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 +134,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 +146,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 +220,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 +241,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) From de74d3f1d358e937ebc0e58fc8e238827585f993 Mon Sep 17 00:00:00 2001 From: Dalton Welch Date: Mon, 9 Oct 2017 11:44:03 -0600 Subject: [PATCH 16/18] Add files via upload --- src/render.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/render.py b/src/render.py index a51b5cc..55ee4c7 100644 --- a/src/render.py +++ b/src/render.py @@ -107,13 +107,6 @@ 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): From 3665215c8b8000ffa7a6e2bbe4056ad7ef545e36 Mon Sep 17 00:00:00 2001 From: micascheid Date: Tue, 10 Oct 2017 14:56:17 -0600 Subject: [PATCH 17/18] Making Isaac happy/adding pygame window position --- src/render.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/render.py b/src/render.py index 55ee4c7..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) From 4f931ebb2ffbddb46f620e1d71fd07aa541f633a Mon Sep 17 00:00:00 2001 From: TOlmsteadWSCU <32274688+TOlmsteadWSCU@users.noreply.github.com> Date: Wed, 11 Oct 2017 12:29:06 -0600 Subject: [PATCH 18/18] Removed .idea directory Its screwen stuff up --- .idea/boids.iml | 11 - .idea/misc.xml | 4 - .idea/modules.xml | 8 - .idea/vcs.xml | 6 - .idea/workspace.xml | 553 -------------------------------------------- 5 files changed, 582 deletions(-) delete mode 100644 .idea/boids.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml 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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -