Guest User

Untitled

a guest
Sep 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. var canvas = $('canvas')[0];
  2.  
  3. if (canvas.getContext) {
  4. var ctx = canvas.getContext('2d'),
  5. w = canvas.width,
  6. h = canvas.height
  7. x1 = 70, // x-coordinate of first circle
  8. y1 = 75, // y-coordinate of first circle
  9. x2 = 145, // x-coordinate of second circle
  10. y2 = y1; // y-coordinate of second circle
  11.  
  12. function init () {
  13. setInterval(draw, 100);
  14. }
  15.  
  16. function frameBuffer () {
  17. var buffer = document.createElement('canvas');
  18.  
  19. buffer.width = canvas.width;
  20. buffer.height = canvas.height;
  21.  
  22. var bufferContext = buffer.getContext('2d');
  23.  
  24. var radgrad = bufferContext.createRadialGradient(x1, y1, 50, x1, y1, 40);
  25. var radgrad2 = bufferContext.createRadialGradient(x2, y2, 145, 50, y2, 40);
  26.  
  27. bufferContext.fillStyle = "rgba(0,0,0,1)";
  28. bufferContext.fillRect(0, 0, w, h);
  29. bufferContext.save();
  30. bufferContext.globalCompositeOperation = "destination-out";
  31.  
  32. // add ellipses
  33. bufferContext.beginPath();
  34. bufferContext.arc(x1, y1, 50, 0, Math.PI * 2, true);
  35. bufferContext.arc(x2, y2, 50, 0, Math.PI * 2, true);
  36. bufferContext.shadowBlur = 20;
  37. bufferContext.shadowColor = "black";
  38.  
  39. radgrad.addColorStop(0, "rgba(0,0,0,0.1)");
  40. radgrad.addColorStop(0.2, "rgba(0, 0, 0, " + (Math.random() + 0.2) + ")");
  41. radgrad.addColorStop(0.8, "rgba(0,0,0," + (Math.random() + 0.8) + ")");
  42. radgrad.addColorStop(1, "rgba(0,0,0,1)");
  43.  
  44. radgrad2.addColorStop(0, "rgba(0,0,0,0.1)");
  45. radgrad2.addColorStop(0.2, "rgba(0, 0, 0, " + (Math.random() + 0.2) + ")");
  46. radgrad2.addColorStop(0.8, "rgba(0,0,0," + (Math.random() + 0.8) + ")");
  47. radgrad2.addColorStop(1, "rgba(0,0,0,1)");
  48.  
  49. bufferContext.fillStyle = radgrad;
  50. bufferContext.fill();
  51. bufferContext.fillStyle = radgrad2;
  52. bufferContext.fill();
  53. bufferContext.restore();
  54.  
  55. return buffer;
  56. }
  57.  
  58. function draw () {
  59. var buffer = frameBuffer();
  60.  
  61. ctx.clearRect(0, 0, w, h);
  62. ctx.drawImage(buffer, 0, 0);
  63. }
  64.  
  65. init();
  66. }
Add Comment
Please, Sign In to add comment