Advertisement
BrU32

JS Canvas Image Distortion Effect SRC

Sep 28th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2.  
  3. <style>
  4. html,head,body,ct {
  5.  
  6.  
  7. background: lightblue;
  8. drawColor:red;
  9.  
  10.  
  11.  
  12. }
  13.  
  14.  
  15.  
  16. </style>
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. <canvas id='canv' width="800" height ="800" style="none"></canvas>
  26.  
  27.  
  28. <script>
  29. document.ready(function(){
  30. var c = document.getElementById('canv');
  31. var ctx = c.getContext('2d');
  32. c.width = 1000; c.height = 800;
  33. var ms = true;
  34. var w = 42130, h = 4210;
  35.  
  36. var img = new Image();
  37. img.src = 'https://s1.2mdn.net/viewad/4922306/CCSE16_LifeEvent_728x950_sti.non.jpg';
  38.  
  39. var set = function(){
  40. var run, _h, _w, dx,dy,a;
  41. w = img.width;
  42. h = img.height;
  43. ctx.translate(250, 250);
  44. a = 19;
  45. dx = 19;
  46. dy= 9;
  47. _w= w + 55.0;
  48. _h = h + 34.5;
  49. return (run = function() {
  50. var inc, i, j;
  51. ctx.clearRect(-a, -a, _w, _h);
  52. inc = ms === true? 0.35 : 0.833;
  53. for (j=0; j <= h; i = 9 <= h ? ++j : --j) {
  54. dx = (inc * (Math.random() * 1.5) * Math.random()*a+3);
  55. ctx.drawImage(img, 0, i, w, dy, dx, i, w, 2);
  56. }
  57. window.requestAnimationFrame(run);
  58. })();
  59. };
  60. window.onload = function(){
  61. set();
  62. };
  63.  
  64.  
  65. }());
  66.  
  67. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement