Advertisement
AZZATSSINS_CYBERSERK

js wat my sc pepes

Mar 7th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. var max_particles = 2500;
  4. var particles = [];
  5. var frequency = 10;
  6. var init_num = max_particles;
  7. var max_time = frequency * max_particles;
  8. var time_to_recreate = false;
  9. // Enable repopolate
  10. setTimeout(function () {
  11.   time_to_recreate = true;
  12. }.bind(this), max_time);
  13. // Popolate particles
  14. popolate(max_particles);
  15. var tela = document.createElement('canvas');
  16. tela.width = $(window).width();
  17. tela.height = $(window).height();
  18. $("body").append(tela);
  19. var canvas = tela.getContext('2d');
  20. var Particle = function () {
  21.   function Particle(canvas) {
  22.     _classCallCheck(this, Particle);
  23.     var random = Math.random();
  24.     this.progress = 0;
  25.     this.canvas = canvas;
  26.     this.center = {
  27.       x: $(window).width() / 2,
  28.       y: $(window).height() / 2
  29.     };
  30.     this.point_of_attraction = {
  31.       x: $(window).width() / 2,
  32.       y: $(window).height() / 2
  33.     };
  34.     if (Math.random() > 0.5) {
  35.       this.x = $(window).width() * Math.random();
  36.       this.y = Math.random() > 0.5 ? -Math.random() - 100 : $(window).height() + Math.random() + 100;
  37.     } else {
  38.       this.x = Math.random() > 0.5 ? -Math.random() - 100 : $(window).width() + Math.random() + 100;
  39.       this.y = $(window).height() * Math.random();
  40.     }
  41.     this.s = Math.random() * 2;
  42.     this.a = 0;
  43.     this.w = $(window).width();
  44.     this.h = $(window).height();
  45.     this.radius = random > .2 ? Math.random() * 1 : Math.random() * 3;
  46.     this.color = random > .2 ? "#694FB9" : "#9B0127";
  47.     this.radius = random > .8 ? Math.random() * 2.2 : this.radius;
  48.     this.color = random > .8 ? "#3CFBFF" : this.color;
  49.   }
  50.   _createClass(Particle, [{
  51.     key: 'calculateDistance',
  52.     value: function calculateDistance(v1, v2) {
  53.       var x = Math.abs(v1.x - v2.x);
  54.       var y = Math.abs(v1.y - v2.y);
  55.       return Math.sqrt(x * x + y * y);
  56.     }
  57.   }, {
  58.     key: 'render',
  59.     value: function render() {
  60.       this.canvas.beginPath();
  61.       this.canvas.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
  62.       this.canvas.lineWidth = 2;
  63.       this.canvas.fillStyle = this.color;
  64.       this.canvas.fill();
  65.       this.canvas.closePath();
  66.     }
  67.   }, {
  68.     key: 'move',
  69.     value: function move() {
  70.       var p1 = {
  71.         x: this.x,
  72.         y: this.y
  73.       };
  74.       var distance = this.calculateDistance(p1, this.point_of_attraction);
  75.       var force = Math.max(100, 1 + distance);
  76.       var attr_x = (this.point_of_attraction.x - this.x) / force;
  77.       var attr_y = (this.point_of_attraction.y - this.y) / force;
  78.       this.x += Math.cos(this.a) * this.s + attr_x;
  79.       this.y += Math.sin(this.a) * this.s + attr_y;
  80.       this.a += Math.random() > 0.5 ? Math.random() * 0.9 - 0.45 : Math.random() * 0.4 - 0.2;
  81.       if (distance < 30 + Math.random() * 100) {
  82.         return false;
  83.       }
  84.       this.render();
  85.       this.progress++;
  86.       return true;
  87.     }
  88.   }]);
  89.   return Particle;
  90. }();
  91. function popolate(num) {
  92.   for (var i = 0; i < num; i++) {
  93.     setTimeout(function (x) {
  94.       return function () {
  95.         // Add particle
  96.         particles.push(new Particle(canvas));
  97.       };
  98.     }(i), frequency * i);
  99.   }
  100.   return particles.length;
  101. }
  102. function createSphera() {
  103.   var radius = 180;
  104.   var center = {
  105.     x: $(window).width() / 2,
  106.     y: $(window).height() / 2
  107.   };
  108. }
  109. function clear() {
  110.   canvas.globalAlpha = 0.08;
  111.   canvas.fillStyle = '#110031';
  112.   canvas.fillRect(0, 0, tela.width, tela.height);
  113.   canvas.globalAlpha = 1;
  114. }
  115. /*
  116.  * Function to update particles in canvas
  117.  */
  118. function update() {
  119.   particles = particles.filter(function (p) {
  120.     return p.move();
  121.   });
  122.   // Recreate particles
  123.   if (time_to_recreate) {
  124.     if (particles.length < init_num) {
  125.       popolate(1);console.log("Ricreo");
  126.     }
  127.   }
  128.   clear();
  129.   requestAnimationFrame(update.bind(this));
  130. }
  131. update();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement