Advertisement
BrU32

JS Canvas Webam With Random BG Color

Oct 28th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <body onload="Gen()">
  2. <video id="video" autoplay hidden>
  3. </video>
  4. <canvas id="canvas" width="500" height="500" style="border:0px solid"/>
  5.  
  6. <script>
  7.  
  8. var video = document.getElementById("video");
  9. var c = document.getElementById("canvas");
  10. var ctx = c.getContext("2d");
  11. var i=0;
  12. var canvas = document.getElementById('canvas');
  13. var context = canvas.getContext('2d');
  14. var video = document.getElementById('video');
  15. var mediaConfig = {video:true,audio:true};
  16. navigator.mediaDevices.getUserMedia(mediaConfig).then(function(stream) {
  17. video.src = this.window.URL.createObjectURL(stream);
  18. video.play();
  19. video.addEventListener("play", function() {i = window.setInterval(function() {
  20. ctx.drawImage(video,0,0,500,500)},1);
  21.  
  22. }, false);
  23. });
  24. function Gen()
  25. {
  26. var text = "";
  27. var possible = "FABCGDEG01234567";
  28. for(var i=0; i!=6; i++)
  29. text+=possible.charAt(Math.floor(Math.random()*possible.length));
  30. document.body.style.backgroundColor=(text);
  31.  
  32. }
  33. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement