Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get cursor
- var cursor = {
- pos: {x: 0, y: 0},
- vel: {x:.1, y: .1},
- mode: "vsine",
- g: -.05,
- a: 1,
- follower: ""
- };
- //screen borders or edge
- const SCREEN_BOUNDARIES = {
- top: 0,
- left: 0,
- bottom: 100,
- right: 100
- }
- //venctor 2
- class Vector2 {
- constructor (x, y) {
- this.x = x;
- this.y = y;
- }
- }
- //cursor function
- function constructor () {
- this.position = new Vector2(SCREEN_BOUNDARIES.right/2,SCREEN_BOUNDARIES.bottom/2);
- this.velocity = new Vector2(0, 0);
- this.acceleration = new Vector2(0, 0);
- this.time = Date.now();
- this.deltaTime = 0;
- this.oldTime = Date.now();
- this.old = {
- time: 0,
- deltaTime: 0,
- velocity: new Vector2(0, 0),
- position: new Vector2(0, 0),
- acceleration: new Vector2(0, 0)
- };
- }
- //mouse animation
- var cursorupdate = setInterval(() => {
- cursor.pos.x = Math.random() * SCREEN_BOUNDARIES.right;
- cursor.pos.y = Math.random() * SCREEN_BOUNDARIES.bottom;
- cursor.velocity = {
- x: 0.01, y: 0.01
- }
- this.time = Date.now();
- this.deltaTime = (this.time - this.old.time)/0.01;
- this.position.x += this.velocity.x * this.deltaTime;
- this.position.y += this.velocity.y * this.deltaTime;
- if (this.position.y < SCREEN_BOUNDARIES.top || this.position.y > SCREEN_BOUNDARIES.bottom) {
- this.velocity.y = -this.velocity.y/200-100;
- }
- if (this.position.x < SCREEN_BOUNDARIES.left || this.position.x > SCREEN_BOUNDARIES.right) {
- this.velocity.x = -this.velocity.x/200-100;
- }
- this.old.time = Date.now();
- }, 50)
- //turn of mouse animation if need
- var cursorsend = setInterval(() => {
- if (cursor.mode !== "off") {
- MPP.client.sendArray([{m:'m', x:cursor.pos.x, y:cursor.pos.y}]);
- }
- }, 25);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement