-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
108 lines (98 loc) · 4.23 KB
/
index.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
<!DOCTYPE html>
<html lang='en'>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row" style="margin: 2em;">
<h1>
Spatially locate device in array!
</h1>
</div>
<div class="row" style="margin: 2em;">
<div class="col-md-8">
<canvas id="canv" style="width: 100%; height: 100%; background-color: #e9ebee;"></canvas>
</div>
<div class="col-md-4">
<div class="container">
<div class="row">
Coordinates: (x: <b id="xcoord"></b>, y: <b id="ycoord"></b>)
</div>
<div class="row">
<button onclick="getGif()" type="button" class="btn btn-primary">Change Image!</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jcanvas/21.0.1/min/jcanvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script>
var $myCanv = $( "#canv" );
var x = 0.5;
var y = 0.5;
imgsource = null;
function drawStuff(x, y, imgsource){
$myCanv.clearCanvas();
$( "#xcoord" ).text(x);
$( "#ycoord" ).text(y);
if(imgsource){
$myCanv.drawImage({
source: imgsource,
fromCenter: true,
scale: 0.3,
x: x*300,
y: y*150
});
}
else{
$myCanv.drawArc({
fillStyle: "#cc0033",
radius: 2,
x: x*300,
y: y*150
}).drawArc({
strokeStyle: "black",
radius: 15,
x: x*300,
y: y*150
});
}
}
drawStuff(x,y, imgsource);
var Http = new XMLHttpRequest();
var url = "http://ec2-35-153-99-16.compute-1.amazonaws.com:5000/send_queue";
var times = setInterval(populateDraw, 1000);
function populateDraw(){
Http.open("GET", url);
Http.send();
Http.onreadystatechange=(e)=>{
console.log(Http.responseText)
var r = JSON.parse(Http.responseText);
if(r.status == 200){
x = r.x;
y = r.y;
}
else{
// x += 0.1
}
}
drawStuff(x,y, imgsource);
}
function getGif(){
giphyURL="https://api.giphy.com/v1/gifs/random?api_key=FhyEnoNtQVEceELiVSPcZpghov1xff2y&tag=harry%20potter&rating=G"
$.ajax({url: giphyURL, success: function(result){
imgsource = result.data.fixed_height_small_url;
console.log(imgsource);
}});
}
</script>
</body>
</html>