Advertisement
AEAEAEAEarray

Untitled

Aug 31st, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //get cursor
  2. var cursor = {
  3.     pos: {x: 0, y: 0},
  4.     vel: {x:.1, y: .1},
  5.     mode: "vsine",
  6.     g: -.05,
  7.     a: 1,
  8.     follower: ""
  9. };
  10.  
  11. //screen borders or edge
  12. const SCREEN_BOUNDARIES = {
  13.     top: 0,
  14.     left: 0,
  15.     bottom: 100,
  16.     right: 100
  17. }
  18.  
  19. //venctor 2
  20. class Vector2 {
  21.     constructor (x, y) {
  22.         this.x = x;
  23.         this.y = y;
  24.     }
  25. }
  26.  
  27. //cursor function
  28. function constructor () {
  29.     this.position = new Vector2(SCREEN_BOUNDARIES.right/2,SCREEN_BOUNDARIES.bottom/2);
  30.     this.velocity = new Vector2(0, 0);
  31.     this.acceleration = new Vector2(0, 0);
  32.  
  33.     this.time = Date.now();
  34.     this.deltaTime = 0;
  35.     this.oldTime = Date.now();
  36.  
  37.     this.old = {
  38.         time: 0,
  39.         deltaTime: 0,
  40.         velocity: new Vector2(0, 0),
  41.         position: new Vector2(0, 0),
  42.         acceleration: new Vector2(0, 0)
  43.     };
  44. }
  45.  
  46. //mouse animation
  47. var cursorupdate = setInterval(() => {
  48.     cursor.pos.x = Math.random() * SCREEN_BOUNDARIES.right;
  49.     cursor.pos.y = Math.random() * SCREEN_BOUNDARIES.bottom;
  50.     cursor.velocity = {
  51.         x: 0.01, y: 0.01
  52.     }
  53.     this.time = Date.now();
  54.             this.deltaTime = (this.time - this.old.time)/0.01;
  55.  
  56.             this.position.x += this.velocity.x * this.deltaTime;
  57.             this.position.y += this.velocity.y * this.deltaTime;
  58.             if (this.position.y < SCREEN_BOUNDARIES.top || this.position.y > SCREEN_BOUNDARIES.bottom) {
  59.                 this.velocity.y = -this.velocity.y/200-100;
  60.             }
  61.  
  62.             if (this.position.x < SCREEN_BOUNDARIES.left || this.position.x > SCREEN_BOUNDARIES.right) {
  63.                 this.velocity.x = -this.velocity.x/200-100;
  64.             }
  65.  
  66.             this.old.time = Date.now();
  67. }, 50)
  68.  
  69. //turn of mouse animation if need
  70. var cursorsend = setInterval(() => {
  71.     if (cursor.mode !== "off") {
  72.         MPP.client.sendArray([{m:'m', x:cursor.pos.x, y:cursor.pos.y}]);
  73.     }
  74. }, 25);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement