tominfnaf

image clicksplosion

Feb 12th, 2022 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <script>
  2.  
  3. var b = document.body;
  4. var imgurl = "https://static.wikia.nocookie.net/minecraft_gamepedia/images/6/64/Potion_of_Healing.gif";
  5. var size = [20, 30];
  6. function rand(min, max)
  7. {
  8. return Math.floor(Math.random() * (max - min + 1) + min)
  9. }
  10. function getSize()
  11. {
  12. return rand(size[0], size[1]);
  13. }
  14. function lerp(a,b,f)
  15. {
  16. return (b-a)*f+a;
  17. }
  18. function heart(x,y)
  19. {
  20. var s = getSize();
  21. x -= s/2;
  22. y -= s/2;
  23. x = Math.floor(x) + rand(-5, 5);
  24. y = Math.floor(y) + rand(-5, 5);
  25. var fx = x + rand(-40, 40);
  26. var fy = y + rand(-40, 40);
  27. var i = document.createElement("img");
  28. i.src = imgurl;
  29. i.style = `pointer-events: none; position: fixed; width: ${s}px; left: ${x}px; top: ${y}px; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; z-index: 1000000;`;
  30. b.appendChild(i);
  31. var f = 0;
  32. var interval;
  33. interval = setInterval(function() {
  34. var _x = Math.floor(lerp(x, fx, f));
  35. var _y = Math.floor(lerp(y, fy, f));
  36. i.style = `pointer-events: none; position: fixed; width: ${s}px; left: ${_x}px; top: ${_y}px; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; z-index: 1000000;`;
  37. i.style.opacity = 1-f;
  38. f += 0.01;
  39. if (f > 1)
  40. {
  41. clearInterval(interval);
  42. b.removeChild(i);
  43. }
  44. }, 10);
  45. }
  46. function bro(x,y)
  47. {
  48. for (var i = 0; i < 5; i++)
  49. {
  50. heart(x,y);
  51. }
  52. }
  53. b.addEventListener("click", function(event){
  54. var x = event.clientX;
  55. var y = event.clientY;
  56. bro(x,y);
  57. });
  58.  
  59. </script>
Add Comment
Please, Sign In to add comment