-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
390 lines (335 loc) · 14.2 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!doctype html>
<html lang="en">
<head>
<title>Hot Dog Cloud!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"
integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<style type="text/css">
canvas {
display: block;
position: fixed;
z-index: 1;
pointer-events: none;
}
.hotDogDetected { color:red; font-size: xx-large; font-weight: bold; text-align: center; }
.notHotDog { color:dimgray; font-size: large; font-weight: bold; text-align: center; }
.analysis { color:silver; font-size: large; text-align: center; }
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="container">
<div class="row align-items-center">
<div class="col-sm">
<h1>Hotdog Cloud</h1>
</div>
<div class="col-sm small text-right">
<a href="https://docs.google.com/presentation/d/1dD4L0T2ms08jJcvriuyi0J6vaKQjI-1E6JLXYoLvtgM/edit?usp=sharing"
target="_blank">Presentation</a><br/>
<a href="https://github.com/ehippy/hotdog" target="_blank">GitHub Project</a>
</div>
</div>
</div>
<div class="container">
<input type="button" class="btn btn-primary btn-lg btn-block"
onclick="document.getElementById('img_capture').click()" value="Take Photo!">
<input type="file" accept="image/*" id="img_capture" capture="camera" style="display: none;">
</div>
<div class="container mt-2">
<div id="list" class="card-deck"></div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"
integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"
integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ"
crossorigin="anonymous"></script>
<script type="text/javascript">
var filePicker = document.getElementById('img_capture');
var list = document.getElementById('list');
var apiBaseURL = "https://hotdog.cloud";
function handleNewFile(e) {
window.dry();
var files = e.srcElement.files;
for (var i = 0; i < files.length; i++) {
var uploadedFileNode = document.createElement('div');
uploadedFileNode.className = 'card';
uploadedFileNode.innerHTML = '<p class="analysis">Analyzing...</p>';
list.insertBefore(uploadedFileNode, list.firstChild);
var file = files[i];
var reader = new FileReader();
reader.addEventListener('loadend', function (e) {
fetch(apiBaseURL + "/requestUploadURL", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: file.name,
type: file.type
})
})
.then(function (response) {
return response.json();
})
.then(function (json) {
return fetch(json.uploadURL, {
method: "PUT",
body: new Blob([reader.result], {type: file.type})
})
})
.then(function () {
uploadedFileNode.innerHTML = '<img class="card-img-bottom" src="//s3.amazonaws.com/secrethotdogbucket/' + file.name + '">';
fetch(apiBaseURL + "/detect", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: file.name
})
})
.then(function (response) {
console.log(response);
return response.json();
})
.then(function (json) {
var hotDogAnalysis = document.createElement('div');
hotDogAnalysis.className = 'card-body';
hotDogAnalysis.innerHTML = "<p class=\"card-text\">"
+ json.Labels.map((label) => {
return label.Name + '(' + Math.round(label.Confidence) + '%)'
}).join(', ')
+ "</p>";
uploadedFileNode.insertBefore(hotDogAnalysis, uploadedFileNode.firstChild);
if (hotDogAnalysis.innerHTML.indexOf('Hot Dog') > 0) {
document.getElementById('toot').play();
window.rain();
var alart = document.createElement('p');
alart.className = 'hotDogDetected';
alart.innerText = 'Hot Dog!!';
hotDogAnalysis.appendChild(alart);
setTimeout(function() { window.dry() }, 3000);
} else {
var alart = document.createElement('p');
alart.className = 'notHotDog';
alart.innerText = 'Not a hot dog.';
hotDogAnalysis.appendChild(alart);
}
});
});
});
reader.readAsArrayBuffer(file);
}
return false;
}
filePicker.addEventListener('change', handleNewFile);
// ya boi da confetti
(function () {
// globals
var canvas;
var ctx;
var W;
var H;
var mp = 100; //max particles
var particles = [];
var angle = 0;
var tiltAngle = 0;
var confettiActive = false;
var animationComplete = true;
var deactivationTimerHandler;
var reactivationTimerHandler;
var animationHandler;
// objects
var particleColors = {
colorOptions: ["DodgerBlue", "OliveDrab", "Gold", "pink", "SlateBlue", "lightblue", "Violet", "PaleGreen", "SteelBlue", "SandyBrown", "Chocolate", "Crimson"],
dualColorOptions: [
{'main': "DodgerBlue", 'alt': 'steelblue'},
{'main': "OliveDrab", 'alt': 'DarkOliveGreen'},
{'main': "Gold", 'alt': 'DarkKhaki'},
{'main': "Pink", 'alt': 'PaleVioletRed'},
{'main': "lightblue", 'alt': 'LightSteelBlue'},
{'main': "Violet", 'alt': 'Orchid'},
{'main': "PaleGreen", 'alt': 'YellowGreen'},
{'main': "SandyBrown", 'alt': 'Peru'},
{'main': "Chocolate", 'alt': 'Sienna'},
{'main': "Crimson", 'alt': 'FireBrick'}],
colorIndex: 0,
colorIncrementer: 0,
colorThreshold: 10,
getColor: function () {
if (this.colorIncrementer >= 10) {
this.colorIncrementer = 0;
this.colorIndex++;
if (this.colorIndex >= this.dualColorOptions.length) {
this.colorIndex = 0;
}
}
this.colorIncrementer++;
return this.dualColorOptions[this.colorIndex];
}
};
function confettiParticle(colorOptions) {
this.x = Math.random() * W; // x-coordinate
this.y = (Math.random() * H) - H; //y-coordinate
this.r = RandomFromTo(10, 30); //radius;
this.d = (Math.random() * mp) + 10; //density;
this.colorOptions = colorOptions;
this.tilt = Math.floor(Math.random() * 10) - 10;
this.tiltAngleIncremental = (Math.random() * 0.07) + .05;
this.tiltAngle = 0;
this.draw = function () {
ctx.beginPath();
ctx.lineWidth = this.r / 2;
ctx.strokeStyle = this.color;
ctx.moveTo(this.x + this.tilt + (this.r / 4), this.y);
ctx.lineTo(this.x + this.tilt, this.y + this.tilt + (this.r / 4));
return ctx.stroke();
}
}
$(document).ready(function () {
SetGlobals();
InitializeButton();
$(window).resize(function () {
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
});
});
function InitializeButton() {
window.rain = function(){
InitializeConfetti();
RestartConfetti();
};
window.dry = function(){
DeactivateConfetti()
};
}
function SetGlobals() {
canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
}
function InitializeConfetti() {
particles = [];
animationComplete = false;
for (var i = 0; i < mp; i++) {
var particleColor = particleColors.getColor();
particles.push(new confettiParticle(particleColor));
}
StartConfetti();
}
function Draw() {
ctx.clearRect(0, 0, W, H);
var results = [];
for (var i = 0; i < mp; i++) {
(function (j) {
results.push(particles[j].draw());
})(i);
}
Update();
return results;
}
function RandomFromTo(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}
function Update() {
var remainingFlakes = 0;
var particle;
angle += 0.01;
tiltAngle += 0.1;
for (var i = 0; i < mp; i++) {
particle = particles[i];
if (animationComplete) return;
if (!confettiActive && particle.y < -15) {
particle.y = H + 100;
continue;
}
stepParticle(particle, i);
if (particle.y <= H) {
remainingFlakes++;
}
CheckForReposition(particle, i);
}
if (remainingFlakes === 0) {
StopConfetti();
}
}
function CheckForReposition(particle, index) {
if ((particle.x > W + 20 || particle.x < -20 || particle.y > H) && confettiActive) {
if (index % 5 > 0 || index % 2 == 0) //66.67% of the flakes
{
repositionParticle(particle, Math.random() * W, -10, Math.floor(Math.random() * 10) - 10);
} else {
if (Math.sin(angle) > 0) {
//Enter from the left
repositionParticle(particle, -5, Math.random() * H, Math.floor(Math.random() * 10) - 10);
} else {
//Enter from the right
repositionParticle(particle, W + 5, Math.random() * H, Math.floor(Math.random() * 10) - 10);
}
}
}
}
function stepParticle(particle, particleIndex) {
particle.tiltAngle += particle.tiltAngleIncremental;
particle.y += (Math.cos(angle + particle.d) + 3 + particle.r / 2) / 2;
particle.x += Math.sin(angle);
particle.tilt = (Math.sin(particle.tiltAngle - (particleIndex / 3))) * 15;
particle.color = particle.tilt > 0 ? particle.colorOptions.main : particle.colorOptions.alt;
}
function repositionParticle(particle, xCoordinate, yCoordinate, tilt) {
particle.x = xCoordinate;
particle.y = yCoordinate;
particle.tilt = tilt;
}
function StartConfetti() {
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
(function animloop() {
if (animationComplete) return null;
animationHandler = requestAnimFrame(animloop);
return Draw();
})();
}
function ClearTimers() {
clearTimeout(reactivationTimerHandler);
clearTimeout(animationHandler);
}
function DeactivateConfetti() {
confettiActive = false;
ClearTimers();
}
function StopConfetti() {
animationComplete = true;
if (ctx == undefined) return;
ctx.clearRect(0, 0, W, H);
}
function RestartConfetti() {
ClearTimers();
StopConfetti();
reactivationTimerHandler = setTimeout(function () {
confettiActive = true;
animationComplete = false;
InitializeConfetti();
}, 100);
}
window.requestAnimFrame = (function () {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
return window.setTimeout(callback, 1000 / 60);
};
})();
})();
</script>
</body>
</html>