Advertisement
BrU32

Untitled

Apr 9th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <style>
  2. body{
  3. filter:invert(180%);
  4. }
  5. </style>
  6. <center>
  7.  
  8. <div id="container">
  9. <video autoplay id="video">
  10. </div>
  11.  
  12.  
  13. <canvas id="canvas" width="500" height="500"></canvas>
  14. <p>
  15.  
  16. <input type="button" value="Move Mouse Here!!" id="save" />
  17.  
  18.  
  19.  
  20. <script>
  21. var video = document.querySelector("#video");
  22.  
  23. // check for getUserMedia support
  24. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
  25.  
  26. if (navigator.getUserMedia) {
  27. // get webcam feed if available
  28. navigator.getUserMedia({video: true}, handleVideo, videoError);
  29. }
  30.  
  31. function handleVideo(stream) {
  32. // if found attach feed to video element
  33. video.src = window.URL.createObjectURL(stream);
  34. }
  35.  
  36. function videoError(e) {
  37. // no webcam found - do something
  38. }
  39. var v,canvas,context,w,h;
  40. var imgtag = document.getElementById('imgtag'); // get reference to img tag
  41. var select = document.getElementById('fileselect'); // get reference to file select input element
  42.  
  43. document.addEventListener('mousemove', function(){
  44. // when DOM loaded, get canvas 2D context and store width and height of element
  45. v = document.getElementById('video');
  46. canvas = document.getElementById('canvas');
  47. context = canvas.getContext('2d');
  48. w = canvas.width++;
  49. h = canvas.height++;
  50.  
  51. },777);
  52.  
  53. function draw(v,c,w,h) {
  54.  
  55. if(v.paused || v.ended) {
  56. return 0; // if no video, exit here52*3529
  57. }
  58. context.drawImage(v,120,50,w,h); // draw video feed to canvas
  59.  
  60. var uri = canvas.toDataURL("image/png").length; // convert canvas to data URI
  61.  
  62. if(uri<352000){ // uncomment line to log URI for testing52*3526
  63. alert('Fully Covered From Light!!');
  64. imgtag.src = uri; // add URI to IMG tag src
  65. }else{
  66. alert('Not Covered From Light!!');
  67. imgtag.src = uri; // add URI to IMG tag src
  68. }
  69. }
  70. document.addEventListener('mouseup',function(e){
  71.  
  72. draw(v,context,w,h); // when save button is clicked, draw video feed to canvas
  73.  
  74. });
  75.  
  76. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement