Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. </head>
  6. <body>
  7. <canvas id="canvas"></canvas>
  8. <script type="text/javascript">
  9. var canvas = document.getElementById('canvas');
  10. var ctx = canvas.getContext('2d');
  11. canvas.height = window.innerHeight-20;
  12. canvas.width = window.innerWidth-20;
  13. var count=1
  14. var points = []
  15. class point{
  16. constructor(x,y,vx,vy){
  17. this.x = x
  18. this.y = y
  19. this.px = this.x
  20. this.py = this.y
  21. this.r = 5
  22. this.vx = vx
  23. this.vy = vy
  24. this.lifespan = 0
  25. this.alive = true
  26. }
  27. draw(){
  28. ctx.moveTo(this.px,this.py)
  29. ctx.lineTo(this.x,this.y)
  30. ctx.stroke()
  31. this.x+=this.vx
  32. this.y+=this.vy
  33. this.dx = this.px-this.x
  34. this.dy = this.py-this.y
  35. this.r = Math.sqrt((this.dx**2) + (this.dy**2))
  36. if(this.lifespan>2){this.alive = false; this.vx=0;this.vy=0;}
  37. if(this.r>50 && this.alive){
  38. this.lifespan++
  39. count++
  40. points.push(new point(this.x,this.y,this.vx,this.vy))
  41. this.vx +=-1+Math.random()*2
  42. this.vy +=-1+Math.random()*2
  43. this.px = this.x
  44. this.py = this.y
  45. ctx.moveTo(this.x,this.y)
  46. ctx.arc(this.x,this.y,2,0,7)
  47. ctx.fill()
  48. }
  49. }
  50. }
  51. points[0]=new point(innerWidth/2,innerHeight-200,0,-1)
  52. function draw(){
  53. for(var i = 0;i<count;i++){
  54. points[i].draw()
  55. }
  56. }
  57. setInterval(draw,16)
  58. </script>
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement