-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvehicle-1.html
155 lines (130 loc) · 5.04 KB
/
vehicle-1.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="JavaScript, Framework, Animation, Natural, System" />
<meta name="description" content="FloraJS simulates natural systems using JavaScript." />
<meta name="viewport" content = "user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<meta name='apple-mobile-web-app-capable' content='yes' />
<meta property='og:title' content='FloraJS' />
<meta property='og:url' content='http://www.florajs.com' />
<meta property='og:site_name' content='FloraJS' />
<title>FloraJS | Simulate natural systems with JavaScript</title>
<link rel="stylesheet" href="css/Burner.min.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="css/Flora.min.css" type="text/css" charset="utf-8" />
<script src="scripts/Burner.min.js" type="text/javascript" charset="utf-8"></script>
<script src="scripts/Flora.min.js" type="text/javascript" charset="utf-8"></script>
<script src="scripts/audio.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
var Gain = new AudioMods.Gain(),
OscA = new AudioMods.Oscillator(),
OscB = new AudioMods.Oscillator(),
Convolver = new AudioMods.Convolver(),
Delay = new AudioMods.Delay();
var OscMin = 150,
OscMax = 200;
OscA.toggle();
OscB.toggle();
Convolver.setEffect(3);
Delay.setDelay(0);
AudioMods.connect(Gain.node, AudioMods.audio_context.destination);
AudioMods.connect(Delay.node, Gain.node);
AudioMods.connect(Convolver.node, Delay.node);
AudioMods.connect(OscA.osc, Convolver.node);
AudioMods.connect(OscB.osc, Convolver.node);
Gain.changeGain(0.25);
//
function createMotor(id, c) {
var color = c || [255, 255, 255];
var motor = document.createElement('div');
motor.id = 'motor' + id;
motor.className = 'motor';
motor.style.cssText = 'position: absolute; top: 7px; left: 4px; width: 8px; height: 2px; background: #666; opacity: 1;';
motor.style.backgroundColor = 'rgb(' + color[0] + ',' + color[1] + ',' + color[2] + ')';
return motor;
}
var rand = Flora.Utils.getRandomNumber;
var world = new Burner.World(document.body, {
gravity: new Burner.Vector(0, 0),
c: 0,
borderWidth: 1,
borderStyle: 'dashed',
borderColor: [100, 100, 100],
width: Flora.Utils.getWindowSize().width / 0.75,
height: Flora.Utils.getWindowSize().height / 0.75,
boundToWindow: false
});
Burner.System.init(function() {
// Vehicles
for (var i = 0; i < 5; i++) {
var agent = this.add('Agent', {
angle: rand(0, 360),
motorSpeed: 2,
minSpeed: 1,
maxSpeed: 10,
width: 20,
height: 20,
location: new Burner.Vector(world.width / 2, world.height / 2),
color: !i ? [255, 255, 255] : [255, 100, 0],
borderColor: !i ? [255, 100, 0] : [255, 150, 50],
borderWidth: 2,
borderStyle: 'solid',
controlCamera: !i,
wrapWorldEdges: true,
sensors: [
this.add('Sensor', {
type: 'heat',
displayRange: !i,
displayConnector: true,
behavior: 'ACCELERATE'
}),
this.add('Sensor', {
type: 'cold',
displayRange: !i,
displayConnector: true,
behavior: 'DECELERATE'
})
],
motorRotation: 0,
beforeStep: function() {
var motor = document.getElementById('motor' + this.id),
a = this.motorRotation;
if (motor) {
motor.style.webkitTransform = 'rotate(' + a + 'deg)';
this.motorRotation += Flora.Utils.map(this.velocity.mag(),
this.minSpeed, this.maxSpeed, 10, 50);
}
}
});
agent.el.appendChild(createMotor(agent.id, !i ? [100, 100, 100] : [255, 255, 255]));
}
// Stimulus
for (var i = 0; i < 10; i++) {
this.add('Stimulus', {
type: 'heat',
location: new Burner.Vector(rand(0, world.width), rand(0, world.height))
});
this.add('Stimulus', {
type: 'cold',
location: new Burner.Vector(rand(0, world.width), rand(0, world.height))
});
}
// Audio agent
this.add('Agent', {
isStatic: true,
visibility: 'hidden',
beforeStep: function() {
var valOscA = Flora.Utils.map(Flora.SimplexNoise.noise(Burner.System.clock * 0.001, 0),
-1, 1, OscMin, OscMax);
OscA.changeFrequency(valOscA);
var valOscB = Flora.Utils.map(Flora.SimplexNoise.noise(Burner.System.clock * -0.001, 0),
-1, 1, OscMin, OscMax);
OscB.changeFrequency(valOscB);
}
});
}, world);
</script>
</body>
</html>