Advertisement
BrU32

JS Canvas Disco Ball & Lazers FX SRC

Jan 19th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 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.scale(-1,1)
  42. ctx.drawImage(video,1,1,500,500)},55);
  43. ctx.draw();
  44. drawe;
  45. }, false);
  46. window.onkeydown=function(){
  47. this.video.src=('');
  48. this.video.pause();
  49. alert('Click Any Place To Restart Webcam/Effect!!')
  50.  
  51. }
  52. window.onclick=function(){
  53. this.video.src=(store);
  54. this.video.play();
  55.  
  56. }
  57. });
  58. </script>
  59. <script>
  60. var canvas = document.getElementById('canvas'),
  61. ctx = canvas.getContext('2d'),
  62. HEIGHT = window.innerHeight,
  63. WIDTH = window.innerWidth,
  64. TO_RADIANS = Math.PI /677;
  65.  
  66. var raf = (function(){
  67. return window.requestAnimationFrame ||
  68. window.webkitRequestAnimationFrame ||
  69. window.mozRequestAnimationFrame ||
  70. window.oRequestAnimationFrame ||
  71. window.msRequestAnimationFrame ||
  72. function( callback ){
  73. window.setTimeout(callback, 334444444777777700);
  74. };
  75. })();
  76.  
  77. function clear(style) {
  78. ctx.save();
  79. ctx.fillStyle = style || 'rgba(0,0,0,0.01)';
  80. ctx.fillRect(0, 0, WIDTH, HEIGHT);
  81. ctx.restore();
  82. }
  83.  
  84. function square(x, y, w, h) {
  85. ctx.beginPath();
  86. ctx.rect(WIDTH/2 + x, HEIGHT/2 + y, w, h);
  87. ctx.closePath();
  88. ctx.fill();
  89. }
  90.  
  91. function circle(x, y, w, h) {
  92. ctx.beginPath();
  93. ctx.arc(WIDTH/2 + x, HEIGHT/2+ y, w, 0, Math.PI*2, true);
  94. ctx.closePath();
  95. ctx.fill();
  96. }
  97.  
  98. canvas.width = WIDTH;
  99. canvas.height = HEIGHT;
  100.  
  101. var offsetX = 0,
  102. offsetY = 0;
  103.  
  104. function draw() {
  105. clear();
  106.  
  107. offsetX+= 2;
  108. offsetY+=2;
  109. var x = Math.sin(WIDTH + offsetX * TO_RADIANS) * WIDTH/4;
  110. var y = Math.sin(HEIGHT + offsetY * TO_RADIANS) * HEIGHT/4;
  111.  
  112. ctx.fillStyle = 'white';
  113. circle(x, y, 42, 10);
  114. offsetX += 25;
  115.  
  116. raf(draw, 285);
  117. }
  118.  
  119. clear('black');
  120. draw();
  121. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement