-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboids.html
42 lines (37 loc) · 924 Bytes
/
boids.html
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
<!DOCTYPE html>
<html>
<body>
<canvas id="field" width="1800" height="900" style="border:1px solid #000000;">
your browser does not support html5 canvas</canvas>
<script src="vector.js"></script>
<script src="boid.js"></script>
<script>
var canvas = document.getElementById("field");
var ctx = canvas.getContext("2d");
var b=new boid(new vector(100,100),new vector(5,5));
var boids=[];
var i;
for (i=0;i<700;i++){
boids.push(new boid(new vector(Math.random()*100+250,Math.random()*100+250),new vector((i%6)+1,(i%6)+2)));
}
function draw(){
ctx.clearRect(0,0,1800,900);
//console.log(b.pos.x+" "+b.vel.x);
ctx.beginPath();
//b.interact();
//b.draw(ctx);
var i;
for (i=0;i<boids.length;i++){
boids[i].interact(boids);
}
for (i=0;i<boids.length;i++){
boids[i].draw(ctx);
}
ctx.closePath();
ctx.stroke();
window.requestAnimationFrame(draw);
}
window.requestAnimationFrame(draw);
</script>
</body>
</html>