Skip to content

Commit 77cfd8a

Browse files
committed
add pbar
1 parent 237e059 commit 77cfd8a

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

html/rps-tf/index.html

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,9 @@ <h1 class="display-4">Rock Paper Scissor++</h1>
6565
<p>
6666
Using artificial intelligence (deep learning) to recognize your hand pose to play RPS
6767
</p>
68-
<div id="loading">
69-
<div class="spinner-grow text-primary" role="status">
70-
<span class="sr-only">Loading...</span>
71-
</div>
72-
<div class="spinner-grow text-secondary" role="status">
73-
<span class="sr-only">Loading...</span>
74-
</div>
75-
<div class="spinner-grow text-success" role="status">
76-
<span class="sr-only">Loading...</span>
77-
</div>
78-
<div class="spinner-grow text-danger" role="status">
79-
<span class="sr-only">Loading...</span>
80-
</div>
81-
<div class="spinner-grow text-warning" role="status">
82-
<span class="sr-only">Loading...</span>
83-
</div>
84-
<div class="spinner-grow text-info" role="status">
85-
<span class="sr-only">Loading...</span>
86-
</div>
87-
<div class="spinner-grow text-dark" role="status">
88-
<span class="sr-only">Loading...</span>
89-
</div>
68+
<div class="progress" style="height: 5px;">
69+
<div id="pBar" class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0"
70+
aria-valuemax="100"></div>
9071
</div>
9172
</div>
9273
</div>

html/rps-tf/index.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ let comScore = 0;
1818
let youSymbol = undefined;
1919
let comSymbol = undefined;
2020
let shootCount = 0;
21+
let loaded = false;
22+
let timer = undefined;
23+
let pBarWidth = 0;
2124

2225
function drawKeypoints(ctx, keypoints) {
2326
function drawPoint(ctx, y, x, r) {
@@ -64,7 +67,7 @@ async function setupCamera() {
6467

6568
const video = document.getElementById('video');
6669
video.onloadeddata = (event) => {
67-
document.getElementById('loading').innerHTML = '<div class="spinner-grow text-primary null-spinner" role="status"><span class="sr-only">Loading...</span></div>';
70+
loaded = true;
6871
document.getElementById('gameInfo').style.display = 'block';
6972
};
7073
const stream = await navigator.mediaDevices.getUserMedia({
@@ -98,7 +101,7 @@ const main =
98101
try {
99102
video = await loadVideo();
100103
} catch (e) {
101-
document.getElementById('loading').innerHTML = '<div class="spinner-grow text-primary null-spinner" role="status"><span class="sr-only">Loading...</span></div>';
104+
loaded = true;
102105
let info = document.getElementById('info');
103106
info.textContent = e.message;
104107
info.style.display = 'block';
@@ -147,7 +150,7 @@ const landmarksRealTime = async (video) => {
147150
if (r.symbol === 'shoot') {
148151
shootCount++;
149152
}
150-
153+
151154
if (r.symbol === 'shoot' && shootCount >= shootThreshold && youSymbol) {
152155
comSymbol = getComputerSymbol();
153156
const winner = getWinner(youSymbol, comSymbol);
@@ -568,6 +571,27 @@ function updateLastSymbols() {
568571
}
569572
}
570573

574+
function startProgressBar() {
575+
function doCheck() {
576+
const pbar = document.getElementById('pBar');
577+
578+
if (loaded) {
579+
clearInterval(timer);
580+
pbar.style = `width: 100%`;
581+
} else {
582+
pBarWidth += 10;
583+
if (pBarWidth > 100) {
584+
pBarWidth = 0;
585+
}
586+
pbar.style = `width: ${pBarWidth}%`;
587+
}
588+
}
589+
590+
timer = setInterval(doCheck, 500);
591+
}
592+
593+
startProgressBar();
594+
571595
navigator.getUserMedia = navigator.getUserMedia ||
572596
navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
573597

0 commit comments

Comments
 (0)