Advertisement
BrU32

JS Webcam Canvas Snow Ball FX SRC

Dec 21st, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. <body bgcolor="black">
  2. <canvas id="canvas"></canvas>
  3. <center>
  4. <body onmousemove="drawe();" onmousedown="drawe" onmouseup="drawe" ommouseover="drawe" onchange="drawe" onload="drawe" onpaint="drawe" ondoubleclick="drawe;">
  5. <video id="video" autoplay hidden>
  6. </video>
  7. <canvas id="canvas" onchange="drawe;" topmost="false" onchange="drawe;" width="500" height="500" style="opacity:1.0;fillColor:none;">
  8. <script>
  9. var ii=1;
  10. var video = document.getElementById("video");
  11. var c = document.getElementById("canvas");
  12. var ctx = c.getContext("2d");
  13. var canvas = document.getElementById('canvas');
  14. var context = canvas.getContext('2d');
  15. var video = document.getElementById('video');
  16. var mediaConfig = { video: true,audio:false};
  17. function drawe(){
  18. var possible = "FABCGDE0123456789";
  19. var text = "";
  20. var canvas = document.getElementById("canvas");
  21. var ctx = canvas.getContext("2d");
  22. for(var i=0; i!=6; i++)
  23. text+=possible.charAt(Math.floor(Math.random()*possible.length))
  24. ctx.strokeStyle="#"+text;
  25. ctx.moveTo(Math.random()*event.x-11,Math.random()*event.x/500);
  26. ctx.lineTo(Math.random()*event.y*11,Math.random()*event.y+500);
  27. ctx.topmost=false;
  28.  
  29. ctx.stroke();
  30. text='';
  31. }
  32. navigator.mediaDevices.getUserMedia(mediaConfig).then(function(stream) {
  33. if(ctx.width==500){event.mouseMove++;}
  34. video.src = this.window.URL.createObjectURL(stream);
  35. var store =video.src;
  36. video.play();
  37. video.addEventListener("play", function() {i = window.setInterval(function() {
  38. canvas.style.opacity-=0.1
  39. canvas.style.opacity++;
  40. ctx.topmost=false;
  41. ctx.drawImage(video,1,1,500,500)},5);
  42. ctx.draw();
  43. drawe;
  44. }, false);
  45. window.onkeydown=function(){
  46. this.video.src=('');
  47. this.video.pause();
  48. alert('Click Any Place To Restart Webcam/Effect!!')
  49.  
  50. }
  51. window.onclick=function(){
  52. this.video.src=(store);
  53. this.video.play();
  54.  
  55. }
  56. });
  57. </script>
  58. <script>
  59. var canvas = document.getElementById('canvas'),
  60. ctx = canvas.getContext('2d'),
  61. HEIGHT = window.innerHeight,
  62. WIDTH = window.innerWidth,
  63. TO_RADIANS = Math.PI /677;
  64.  
  65. var raf = (function(){
  66. return window.requestAnimationFrame ||
  67. window.webkitRequestAnimationFrame ||
  68. window.mozRequestAnimationFrame ||
  69. window.oRequestAnimationFrame ||
  70. window.msRequestAnimationFrame ||
  71. function( callback ){
  72. window.setTimeout(callback, 334444444777777700);
  73. };
  74. })();
  75.  
  76. function clear(style) {
  77. ctx.save();
  78. ctx.fillStyle = style || 'rgba(0,0,0,0.01)';
  79. ctx.fillRect(0, 0, WIDTH, HEIGHT);
  80. ctx.restore();
  81. }
  82.  
  83. function square(x, y, w, h) {
  84. ctx.beginPath();
  85. ctx.rect(WIDTH/2 + x, HEIGHT/2 + y, w, h);
  86. ctx.closePath();
  87. ctx.fill();
  88. }
  89.  
  90. function circle(x, y, w, h) {
  91. ctx.beginPath();
  92. ctx.arc(WIDTH/2 + x, HEIGHT/2+ y, w, 0, Math.PI*2, true);
  93. ctx.closePath();
  94. ctx.fill();
  95. }
  96.  
  97. canvas.width = WIDTH;
  98. canvas.height = HEIGHT;
  99. var size=10;
  100. var offsetX = 0,
  101. offsetY = 0;
  102.  
  103. function draw() {
  104. clear();
  105. offsetX+=2;
  106. offsetY+=22;
  107. var x = Math.sin(WIDTH + offsetX * TO_RADIANS) * WIDTH/4;
  108. var y = Math.sin(HEIGHT + offsetY * TO_RADIANS) * HEIGHT/4;
  109. ctx.fillStyle = 'white';
  110. size--;
  111. circle(x,y,size--,size++)
  112. circle(x,y,size++,size++);
  113. offsetX += 32;
  114. raf(draw,3)
  115. if(size==32){
  116. size++;
  117. }
  118. else{
  119. size--;
  120. }
  121. }
  122.  
  123. clear('black');
  124. draw();
  125. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement