-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.js
93 lines (76 loc) · 1.96 KB
/
site.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
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
var $motionBox = $('.motion-box');
var scale = 10;
var isActivated = false;
var isTargetInSight = false;
var isKnockedOver = false;
var lostTimeout;
var canvas = document.getElementById('heat');
function initSuccess() {
DiffCamEngine.start();
}
function initError() {
alert('Something went wrong.');
}
function startComplete() {
setTimeout(activate, 500);
}
function activate() {
isActivated = true;
play('activated');
}
function capture(payload) {
if (!isActivated || isKnockedOver) {
return;
}
var box = payload.motionBox;
if (box) {
var right = box.x.min * scale + 1;
var top = box.y.min * scale + 1;
var width = (box.x.max - box.x.min) * scale;
var height = (box.y.max - box.y.min) * scale;
var speed = (right+payload.score/50)+"kmh";
document.getElementById('speed').innerText =`Kecepatan :${speed}`;
document.getElementById('jarak').innerText =`Jarak :${right}`;
document.getElementById('atas').innerText =`Atas :${top}`;
document.getElementById('lebar').innerText =`Lebar :${width}`;
document.getElementById('tinggi').innerText =`Tinggi :${height}`;
document.getElementById('heatmap').innerText="Heat :"+ payload.score;
$motionBox.css({
display: 'block',
right: right,
top: top,
width: width,
height: height
});
if (!isTargetInSight) {
isTargetInSight = true;
play('fire');
} else {
//play('i-see-you');
}
clearTimeout(lostTimeout);
lostTimeout = setTimeout(declareLost, 2000);
}
if (payload.checkMotionPixel(0, 0)) {
// knockOver();
}
}
function declareLost() {
isTargetInSight = false;
play('target-lost');
$motionBox.hide();
}
function play(audioId) {
$('#audio-' + audioId)[0].play();
}
DiffCamEngine.init({
video: document.getElementById('video'),
motionCanvas: canvas,
captureIntervalTime: 50,
includeMotionBox: true,
includeMotionPixels: true,
initSuccessCallback: initSuccess,
initErrorCallback: initError,
startCompleteCallback: startComplete,
captureCallback: capture
});