Skip to content

Instantly share code, notes, and snippets.

@quadrochave
Created August 28, 2019 02:28
Show Gist options
  • Save quadrochave/7d1fb4efd930c40abf1e74fc5a5a1d2c to your computer and use it in GitHub Desktop.
Save quadrochave/7d1fb4efd930c40abf1e74fc5a5a1d2c to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/risihos
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
<div class="floatWindow"></div>
<script id="jsbin-javascript">
function introMenu() {
var startCamHtml ='<button id="startCam">Jogo</button>' ;
var cameraHtml = '<video id="camera" autoplay></video>';
var snapshotCanvasHtml = '<button id="capture">captura</button>';
var captureButtonHtml ='<canvas id="snapshot" width=320 height=240></canvas>';
$("body").append(startCamHtml);
startCam.onclick = function() {
var startCam = document.getElementById('startCam');
$(".floatWindow")
.append(cameraHtml)
.append(snapshotCanvasHtml)
.append(captureButtonHtml);
captureFromCam();
}
}
function captureFromCam() {
var camera = document.getElementById('camera');
var snapshotCanvas = document.getElementById('snapshot');
var captureButton = document.getElementById('capture');
var handleSuccess = function(stream) {
// Attach the video stream to the video element and autoplay.
camera.srcObject = stream;
};
captureButton.onclick = function() {
var context = snapshot.getContext('2d');
// Draw the video frame to the canvas.
context.drawImage(camera, 0, 0, snapshotCanvas.width,
snapshotCanvas.height);
};
navigator.mediaDevices.getUserMedia({video: true})
.then(handleSuccess);
}
introMenu();
</script>
<script id="jsbin-source-javascript" type="text/javascript">function introMenu() {
var startCamHtml ='<button id="startCam">Jogo</button>' ;
var cameraHtml = '<video id="camera" autoplay></video>';
var snapshotCanvasHtml = '<button id="capture">captura</button>';
var captureButtonHtml ='<canvas id="snapshot" width=320 height=240></canvas>';
$("body").append(startCamHtml);
startCam.onclick = function() {
var startCam = document.getElementById('startCam');
$(".floatWindow")
.append(cameraHtml)
.append(snapshotCanvasHtml)
.append(captureButtonHtml);
captureFromCam();
}
}
function captureFromCam() {
var camera = document.getElementById('camera');
var snapshotCanvas = document.getElementById('snapshot');
var captureButton = document.getElementById('capture');
var handleSuccess = function(stream) {
// Attach the video stream to the video element and autoplay.
camera.srcObject = stream;
};
captureButton.onclick = function() {
var context = snapshot.getContext('2d');
// Draw the video frame to the canvas.
context.drawImage(camera, 0, 0, snapshotCanvas.width,
snapshotCanvas.height);
};
navigator.mediaDevices.getUserMedia({video: true})
.then(handleSuccess);
}
introMenu();</script></body>
</html>
function introMenu() {
var startCamHtml ='<button id="startCam">Jogo</button>' ;
var cameraHtml = '<video id="camera" autoplay></video>';
var snapshotCanvasHtml = '<button id="capture">captura</button>';
var captureButtonHtml ='<canvas id="snapshot" width=320 height=240></canvas>';
$("body").append(startCamHtml);
startCam.onclick = function() {
var startCam = document.getElementById('startCam');
$(".floatWindow")
.append(cameraHtml)
.append(snapshotCanvasHtml)
.append(captureButtonHtml);
captureFromCam();
}
}
function captureFromCam() {
var camera = document.getElementById('camera');
var snapshotCanvas = document.getElementById('snapshot');
var captureButton = document.getElementById('capture');
var handleSuccess = function(stream) {
// Attach the video stream to the video element and autoplay.
camera.srcObject = stream;
};
captureButton.onclick = function() {
var context = snapshot.getContext('2d');
// Draw the video frame to the canvas.
context.drawImage(camera, 0, 0, snapshotCanvas.width,
snapshotCanvas.height);
};
navigator.mediaDevices.getUserMedia({video: true})
.then(handleSuccess);
}
introMenu();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment