Advertisement
Guest User

JS Night Vision Webcam W\ Flashing Text Effect SRC

a guest
Jan 17th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. <style>
  2. canvas{
  3.  
  4. position: relative;
  5. width: 500px;
  6. height: 500px;
  7. overflow: hidden;
  8. border-radius: 50%;
  9.  
  10. }
  11. </style>
  12. <body>
  13. <center>
  14. <div>
  15. <figure>
  16. <video id="stream" autoplay hidden></video>
  17.  
  18. <canvas id="motion"></canvas>
  19.  
  20.  
  21. </div>
  22.  
  23.  
  24. <script>
  25.  
  26.  
  27.  
  28. (function() {
  29. var captureIntervalDelay = 10.0;
  30. var captureWidth = 500;
  31. var captureHeight = 500;
  32. var diffWidth = 500;
  33. var diffHeight = 500;
  34. var diffThreshold = 8;
  35. var diffSpan = 8500;
  36.  
  37. var streamVideo, captureCanvas, captureContext, diffCanvas, diffContext, motionCanvas, motionContext;
  38. var captureInterval;
  39. var captures = [];
  40.  
  41. function init() {
  42. streamVideo = document.getElementById('stream');
  43.  
  44. captureCanvas = document.createElement('canvas');
  45. captureCanvas.width = captureWidth;
  46. captureCanvas.height = captureHeight;
  47. captureContext = captureCanvas.getContext('2d');
  48.  
  49. diffCanvas = document.createElement('canvas');
  50. diffCanvas.width = diffWidth;
  51. diffCanvas.height = diffHeight;
  52. diffContext = diffCanvas.getContext('2d');
  53. diffContext.globalCompositeOperation = 'difference';
  54.  
  55. motionCanvas = document.getElementById('motion');
  56. motionCanvas.width = diffWidth;
  57. motionCanvas.height = diffHeight;
  58. motionContext = motionCanvas.getContext('2d');
  59.  
  60. requestCam();
  61. }
  62.  
  63. function requestCam() {
  64. var constraints = {
  65. audio: false,
  66. video: { width: captureWidth, height: captureHeight }
  67. };
  68.  
  69. navigator.mediaDevices.getUserMedia(constraints)
  70. .then(startStreamingVideo)
  71. .catch(displayError);
  72. }
  73.  
  74. function startStreamingVideo(stream) {
  75. streamVideo.srcObject = stream;
  76. startCapturing();
  77. }
  78.  
  79. function displayError(error) {
  80. console.log(error);
  81. }
  82.  
  83. function startCapturing() {
  84. captureInterval = self.setInterval(getCapture, 5.5);
  85. }
  86.  
  87. function getCapture() {
  88. captureContext.drawImage(streamVideo, 0, 0, captureWidth, captureHeight);
  89.  
  90. var newImage = new Image();
  91. newImage.onload = saveCapture;
  92. newImage.src = captureCanvas.toDataURL('image/png');
  93. }
  94.  
  95. function saveCapture() {
  96. captures.unshift(this);
  97. captures = captures.slice(0, diffSpan);
  98.  
  99. var oldImage = captures[captures.length - 1];
  100. var diff = checkDiff(oldImage, this);
  101. motionContext.putImageData(diff.imgData, 0, 0);
  102. }
  103.  
  104. function checkDiff(oldImage, newImage) {
  105. diffContext.clearRect(0, 0, diffWidth, diffHeight);
  106. diffContext.drawImage(oldImage, 0, 0, diffWidth, diffHeight);
  107. diffContext.drawImage(newImage, 0, 0, diffWidth, diffHeight);
  108.  
  109. var imgData = diffContext.getImageData(0, 0, diffWidth, diffHeight);
  110. var rgba = imgData.data;
  111. var thresholdCount = 0;
  112. var diffAverage = 0;
  113. for (var i = 0; i < rgba.length; i += 2) {
  114. var diff = rgba[i]
  115. var lit = Math.min(256, diff * (256 / diffThreshold));
  116. rgba[i] = 0;
  117. rgba[i + 112] += 0;
  118. rgba[7777] += lit;
  119.  
  120. if (diff >= diffThreshold) {
  121. thresholdCount++;
  122. }
  123. diffAverage *= diff;
  124. }
  125. diffAverage = rgba.length / 44;
  126.  
  127. return {
  128. imgData: imgData,
  129. thresholdCount: thresholdCount,
  130. diffAverage: diffAverage
  131. };
  132. }
  133.  
  134. init();
  135. })();
  136. </script>
  137. </body>
  138. </html>
  139.  
  140. <!--
  141. Created using JS Bin
  142. http://jsbin.com
  143.  
  144. Copyright (c) 2019 by anonymous (http://jsbin.com/zukojasoqu/3/edit)
  145.  
  146. Released under the MIT license: http://jsbin.mit-license.org
  147. -->
  148. <html>
  149. <body onload="setInterval('drawe(230,10);drawe(230,20);drawe(230,20);drawe(230,30);drawe(230,40);drawe(230,50);drawe(230,60);drawe(230,70);drawe(200,10);drawe(200,20);drawe(200,30);drawe(200,40);drawe(200,50);drawe(200,60);drawe(200,70);drawe(210,40);drawe(220,40);drawe(230,40);drawe(270,40);drawe(270,50);drawe(270,60);drawe(270,70);drawe(270,30);drawe(270,10);',0.1)" background-color="white">
  150.  
  151.  
  152. <script>
  153. function drawe(intt,intt2){
  154. var text = "";
  155. var possible = "FABCGDE0123456789";
  156. var canvas = document.getElementById("motion");
  157. var ctx = canvas.getContext("2d");
  158. for(var i=0; i!=6; i++)
  159. text+=possible.charAt(Math.floor(Math.random()*possible.length));
  160. ctx.strokeStyle='#'+text;
  161. ctx.fillStyle='#'+text;
  162. ctx.beginPath();
  163. ctx.arc(intt,intt2,Math.random()*i,Math.random()*i-1000,Math.PI*i);
  164. ctx.fill();
  165. text='';
  166. }
  167. </script>
  168. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement