/
Arrive.test.html
81 lines (72 loc) · 1.77 KB
/
Arrive.test.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
<!DOCTYPE html>
<!--
/**
* @author Raoul Harel
* @license The MIT license (LICENSE.txt)
* @copyright 2015 Raoul Harel
* @url https://github.com/rharel/js-steering-behaviors
*/
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Arrive Visual Test [js-steering-behaviors]</title>
<link rel="stylesheet" href="css/visual_test.css">
<script src="../../dist/steering_behaviors.js"></script>
<script src="js/Simulation.js"></script>
<script src="js/Renderer.js"></script>
</head>
<body>
<h1>Arrive behavior visual test</h1>
<script>
(function() {
const canvas = document.createElement('canvas');
const _2d = canvas.getContext('2d');
canvas.width = 500;
canvas.height = 500;
document.body.appendChild(canvas);
const simulation = new Simulation(canvas.width, canvas.height);
const renderer = new Renderer
(
{
size: new SB.Vector(30, 40),
stroke: 'black',
fill: 'lightgreen',
line_width: 2
}
);
const agent =
{
vehicle: new SB.Vehicle
({
position: new SB.Vector(50, 50),
max_thrust: 200,
max_speed: 100
}),
behavior: new SB.Behavior.Arrive
(
new SB.Vector(450, 450),
100,
100
)
};
simulation.agents.push(agent);
let t_before = new Date();
function main()
{
const t_now = new Date();
const dt = (t_now - t_before) / 1000;
t_before = t_now;
simulation.step(dt === 0 ? 0.001 : dt);
renderer.render_background(_2d);
simulation.agents.forEach(agent =>
{
renderer.render_vehicle(_2d, agent.vehicle, agent.style);
});
setTimeout(() => requestAnimationFrame(main), 15);
}
main();
})();
</script>
</body>
</html>