-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathflock.html
97 lines (78 loc) · 2.51 KB
/
flock.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>Flock</title>
</head>
<!-- <button id="triggerButton">Chirrrp</button> -->
<body>
<script src="bird.js"></script>
<script src="flock.js"></script>
<script src="xgui.js"></script>
<script>
window.addEventListener("load", function(){
gui = new xgui( {width: 640, height: 660, backgroundColor: "rgb(65, 104, 137)", frontColor: "rgb(153, 193, 226)", dimColor: "rgb(90, 137, 177)"} );
var button = new gui.Button({x: 90+100, y: 5, radius: 25, text: "Chirp", height: 20});
var running = false;
button.value.bind(function(a, up){
if(up) {
if (running) {
running = false;
}
else{
running = true;
}
}
});
var options = Object.keys(generatePresets());
var type = "speckled-throated-spew";
var intervalID = null;
var ac;
window.AudioContext = window.AudioContext || window.webkitAudioContext;
if (window.AudioContext) ac = new AudioContext();
var flocks = [new flock(ac, 5, type), new flock(ac, 5, type), new flock(ac, 5, type), new flock(ac, 5, type)];
function flyTheFlock(flocks, interval){
var increment = 10;
var zPos = 5;
var xVel = 10;
var count = 0;
flocks.forEach(function(flock){
flock.position = {x:-100,y:0, z:5};
flock.velocity = {x:10, y:0, z:0};
});
intervalID = window.setInterval(function(){
if (running){
var birds = flocks[count++];
if (birds.position.x > 100){
increment = -10;
xVel = -10;
zPos = 20;
}else if (birds.position.x < -100){
increment = 10;
xVel = 10;
zPos = 5;
}
birds.position.x += increment;
birds.position.z = zPos;
birds.velocity = {x:xVel, y:0, z:0};
birds.chirp();
count = count%flocks.length;
}
}, interval);
return intervalID;
}
var dropdown = new gui.DropDown( {x: 280, y: 7, height:20, width:148, values:options , texts:options } );
dropdown.value.bind(function(key){
if (intervalID) window.clearInterval(intervalID);
flocks = null;
flocks = [new flock(ac, 5, key), new flock(ac, 5, key), new flock(ac, 5, key), new flock(ac, 5, key)];
intervalID = flyTheFlock(flocks, 700);
});
document.body.appendChild( gui.getDomElement() );
intervalID = flyTheFlock(flocks, 700);
});
</script>
</body>