Advertisement
BrU32

JS Canvas Webcam Random Colored Rect Generator Overlay SRC

Sep 28th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <center>
  2. <body onload="setInterval(drawe,5)" background-color="black">
  3. <video id="video" autoplay hidden>
  4. </video>
  5. <canvas id="canvas" width="500" height="500" style="drawColor:#FFFFFF">
  6. <script>
  7. var video = document.getElementById("video");
  8. var c = document.getElementById("canvas");
  9. var ctx = c.getContext("2d");
  10. var i=0;
  11. var mediaConfig = { video:true,audio:true};
  12. navigator.mediaDevices.getUserMedia(mediaConfig).then(function(stream) {
  13. video.src = this.window.URL.createObjectURL(stream);
  14. video.play();
  15. video.addEventListener("play", function() {i = window.setInterval(function() {
  16. ctx.drawImage(video,0,0,500,500)},.9);
  17. }, false);
  18. });
  19.  
  20. var ii=500;
  21. function drawe(){
  22. ii++;
  23. var text = "";
  24. var possible = "FABCGDE0123456789";
  25. var canvas = document.getElementById("canvas");
  26. var ctx = canvas.getContext("2d");
  27. for(var i=0; i!=6; i++)
  28. text+=possible.charAt(Math.floor(Math.random()*possible.length));
  29. ctx.strokeStyle='#'+text;
  30. ctx.fillStyle="#"+text;
  31. var c = document.getElementById("canvas");
  32. var ctx = c.getContext("2d");
  33. ctx.beginPath();
  34. ctx.rect(Math.random()*ii,Math.random()*ii,Math.random()*ii,Math.random()*ii,ii*Math.PI);
  35. ctx.fill();
  36. ctx.fillPath();
  37.  
  38. text='';
  39. }
  40. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement