-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
68 lines (55 loc) · 1.83 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const flock = [];
let radius = 30;
let num = 200;
function setup() {
// createCanvas(600, 400);
createCanvas(windowWidth, windowHeight);
for(let i = 0; i< num; i++){
flock.push(new Bird());
}
// let boundary = new Boundary(width/2, height/2, width/2, height/2);
// let quadtree = new QuadTree(boundary, 4);
// for(let i = 0; i< 10; i++){
// let b = new Bird();
// quadtree.insert(b);
// }
}
function draw() {
// put drawing code here
background(81);
// -------------------------------------------------------------------------------------------------------------------
// for(let b of flock){
// nearest_neighbour = [];
// for(let other of flock){
// let d = dist(b.position.x, b.position.y, other.position.x, other.position.y);
// if(other!=b && d < radius){
// nearest_neighbour.push(other);
// }
// }
// b.apply_rules(nearest_neighbour);
// }
//--------------------------------------------------------------------------------------------------------------------
let boundary = new Boundary(width/2, height/2, width/2, height/2);
let quadtree = new QuadTree(boundary, 4);
for(let b of flock){
quadtree.insert(b);
}
quadtree.display();
for(let b of flock){
let range = new Range(b.position.x, b.position.y, radius);
let neighbour = quadtree.get_points(range);
b.apply_rules(neighbour);
}
//------------------------------------------------------------------------------------------------------------------------
// let b = flock[0];
// let range = new Range(b.position.x, b.position.y, radius);
// let neighbour = quadtree.get_points(range);
// b.apply_rules(neighbour);
// b.update();
// console.log(neighbour.length);
//------------------------------------------------------------------------------------------------------------------------
for(let b of flock){
b.update();
b.show();
}
}