-
Notifications
You must be signed in to change notification settings - Fork 2
/
designer.js
59 lines (46 loc) · 1.33 KB
/
designer.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
var canvas;
var ctx;
var tank;
function min(a, b) {
if (a < b) {
return a;
} else {
return b;
}
}
function deg2rad(angle) {
return angle*Math.PI/180;
}
function update() {
var color = document.getElementsByName('color')[0].value;
var sensors = new Array();
for (i = 0; i < 10; i += 1) {
var range = document.getElementsByName('s'+i+'r')[0].value;
var angle = document.getElementsByName('s'+i+'a')[0].value;
var width = document.getElementsByName('s'+i+'w')[0].value;
var turret = document.getElementsByName('s'+i+'t')[0].checked;
sensors[i] = [min(range, 100),
deg2rad(angle % 360),
deg2rad(width % 360),
turret];
}
tank = new Tank(ctx, 200, 200, color, sensors);
}
function design() {
var frame = 0;
var loop_id;
canvas = document.getElementById('design');
ctx = canvas.getContext('2d');
canvas.width = 200;
canvas.height = 200;
tank = new Tank(ctx, 200, 200, "#c0c0c0", []);
function update() {
var turret = frame * Math.PI / 90;
frame += 1;
canvas.width = canvas.width;
tank.set_state(100, 100, Math.PI * 1.5, turret, 0, 0);
tank.draw_sensors();
tank.draw_tank();
}
loop_id = setInterval(update, 66);
}