Advertisement
AEAEAEAEarray

cursor animation

Aug 29th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Vector2 = class Vector2 {
  2.     constructor (x, y) {
  3.         this.x = x;
  4.         this.y = y;
  5.     }
  6. }
  7.  
  8.  
  9.  
  10. const SCREEN_BOUNDARIES = {
  11.     top: 0,
  12.     left: 0,
  13.     bottom: 100,
  14.     right: 100
  15. }
  16.  
  17. class Cursor {
  18.     constructor () {
  19.         this.position = new Vector2(SCREEN_BOUNDARIES.right/2,SCREEN_BOUNDARIES.bottom/2);
  20.         this.velocity = new Vector2(0, 0);
  21.         this.acceleration = new Vector2(0, 0);
  22.  
  23.         this.time = Date.now();
  24.         this.deltaTime = 0;
  25.         this.oldTime = Date.now();
  26.  
  27.         this.old = {
  28.             time: 0,
  29.             deltaTime: 0,
  30.             velocity: new Vector2(0, 0),
  31.             position: new Vector2(0, 0),
  32.             acceleration: new Vector2(0, 0)
  33.         };
  34.     }
  35.  
  36.     func() {
  37.  
  38.     }
  39.  
  40.     defaultDVD() {
  41.         this.position = new Vector2(Math.random() * SCREEN_BOUNDARIES.right, Math.random() * SCREEN_BOUNDARIES.bottom);
  42.         this.velocity = new Vector2(1, 2);
  43.  
  44.         this.func = () => {
  45.             this.time = Date.now();
  46.             this.deltaTime = (this.time - this.old.time)/1000;
  47.  
  48.             this.position.x += this.velocity.x * this.deltaTime;
  49.             this.position.y += this.velocity.y * this.deltaTime;
  50.            
  51.             if (this.position.y < SCREEN_BOUNDARIES.top || this.position.y > SCREEN_BOUNDARIES.bottom) {
  52.                 this.velocity.y = -this.velocity.y;
  53.             }
  54.  
  55.             if (this.position.x < SCREEN_BOUNDARIES.left || this.position.x > SCREEN_BOUNDARIES.right) {
  56.                 this.velocity.x = -this.velocity.x;
  57.             }
  58.  
  59.             this.old.time = Date.now();
  60.         }
  61.     }
  62.  
  63.     defaultLeaf() {
  64.         this.position = new Vector2(SCREEN_BOUNDARIES.right/2, SCREEN_BOUNDARIES.top);
  65.         this.velocity = new Vector2(1, 2);
  66.  
  67.         let angle = 0;
  68.  
  69.         let width = 5;
  70.  
  71.         this.func = () => {
  72.             this.time = Date.now();
  73.             this.deltaTime = (this.time - this.old.time)/1000;
  74.  
  75.             angle += 0.1;
  76.  
  77.             this.position.x = (((Math.floor(Math.sin(angle) * 100)/100) * width)) + 50;
  78.             // console.log(angle + ": " + this.position.x);
  79.            
  80.             this.velocity.y = (Math.abs(this.old.position.x - this.position.x)/2) - Math.sin(angle*2)/((10 + 5)/width) + 0.01;
  81.  
  82.             this.position.y += this.velocity.y/1.5;
  83.  
  84.             if (this.position.y > SCREEN_BOUNDARIES.bottom) {
  85.                 this.position.y = SCREEN_BOUNDARIES.top;
  86.             }
  87.  
  88.             this.old.position.x = this.position.x;
  89.             this.old.time = Date.now();
  90.         }
  91.     }
  92.  
  93.     defaultFigure() {
  94.         this.position = new Vector2(SCREEN_BOUNDARIES.right/2, SCREEN_BOUNDARIES.top);
  95.         this.velocity = new Vector2(1, 2);
  96.  
  97.         let angle = 0;
  98.  
  99.         let width = 10;
  100.         let height = 10;
  101.  
  102.         this.func = () => {
  103.             this.time = Date.now();
  104.             this.deltaTime = (this.time - this.old.time)/1000;
  105.  
  106.             angle += 0.1;
  107.  
  108.             this.position.x = (((Math.floor(Math.sin(angle) * 100)/100) * width)) + 50;
  109.             // console.log(angle + ": " + this.position.x);
  110.            
  111.             this.velocity.y = 50 - height + (Math.sin(angle*2)/((10 + 5)/width) + 1) * height;
  112.  
  113.             this.position.y = this.velocity.y
  114.  
  115.             if (this.position.y > SCREEN_BOUNDARIES.bottom) {
  116.                 this.position.y = SCREEN_BOUNDARIES.top;
  117.             }
  118.  
  119.             this.old.position.x = this.position.x;
  120.             this.old.time = Date.now();
  121.         }
  122.     }
  123.  
  124.     defaultFigureB() {
  125.         this.position = new Vector2(SCREEN_BOUNDARIES.right/2, SCREEN_BOUNDARIES.top);
  126.         this.velocity = new Vector2(1, 2);
  127.  
  128.         let angle = 0;
  129.  
  130.         let width = 10;
  131.         let height = 10;
  132.  
  133.         let r = 0;
  134.  
  135.         this.func = () => {
  136.             this.time = Date.now();
  137.             this.deltaTime = (this.time - this.old.time)/1000;
  138.  
  139.             angle += 0.1;
  140.  
  141.             this.position.x = ((Math.floor(Math.sin(2 * angle) * 100)/100) * width) + 50
  142.             // console.log(angle + ": " + this.position.x);
  143.  
  144.             this.position.y = ((Math.floor(Math.sin(3 * angle) * 100)/100) * width) + 50
  145.  
  146.             if (this.position.y > SCREEN_BOUNDARIES.bottom) {
  147.                 this.position.y = SCREEN_BOUNDARIES.top;
  148.             }
  149.  
  150.             this.old.position.x = this.position.x;
  151.             this.old.time = Date.now();
  152.  
  153.         }
  154.     }
  155.  
  156.     defaultFigureC() {
  157.         this.position = new Vector2(SCREEN_BOUNDARIES.right/2, SCREEN_BOUNDARIES.bottom/2);
  158.         this.velocity = new Vector2(1, 2);
  159.  
  160.         let angle = 0;
  161.  
  162.         let width = 10;
  163.         let height = 10;
  164.  
  165.         let r = 0;
  166.  
  167.         let x = 50;
  168.         let velx = 2/5;
  169.         let vely = 2/7;
  170.         let y = 50;
  171.  
  172.         this.func = () => {
  173.             this.time = Date.now();
  174.             this.deltaTime = (this.time - this.old.time)/1000;
  175.  
  176.             angle += 0.01;
  177.  
  178.             this.position.x = ((Math.floor(Math.sin(8 * angle) * 100)/100) * width) + x;
  179.             // console.log(angle + ": " + this.position.x);
  180.  
  181.             this.position.y = ((Math.floor(Math.sin(13 * angle) * 100)/100) * width) + y;
  182.  
  183.             // if (this.position.y > SCREEN_BOUNDARIES.bottom) {
  184.             //     this.position.y = SCREEN_BOUNDARIES.top;
  185.             // }
  186.  
  187.             x += velx;
  188.             y += vely;
  189.  
  190.             if (x > 90 || x < 10) {
  191.                 velx = -velx;
  192.             }
  193.  
  194.             if (y > 90 || y < 10) {
  195.                 vely = -vely;
  196.             }
  197.  
  198.             this.old.position.x = this.position.x;
  199.             this.old.time = Date.now();
  200.         }
  201.     }
  202.  
  203.     rave() {
  204.         this.position = new Vector2(SCREEN_BOUNDARIES.right/2, SCREEN_BOUNDARIES.bottom/2);
  205.         this.velocity = new Vector2(1, 2);
  206.  
  207.         let angle = 0;
  208.  
  209.         let width = 10;
  210.         let height = 10;
  211.  
  212.         let r = 0;
  213.  
  214.         this.func = () => {
  215.             this.time = Date.now();
  216.             this.deltaTime = (this.time - this.old.time)/1000;
  217.  
  218.             angle += 0.1;
  219.  
  220.             this.position.x = ((Math.floor(Math.cos(2 * angle) * 100)/100) * width) + 50
  221.             // console.log(angle + ": " + this.position.x);
  222.  
  223.             this.position.y = ((Math.floor(Math.tan(3 * angle) * 100)/100) * width) + 50
  224.  
  225.             if (this.position.y > SCREEN_BOUNDARIES.bottom) {
  226.                 this.position.y = SCREEN_BOUNDARIES.top;
  227.             }
  228.  
  229.             this.old.position.x = this.position.x;
  230.             this.old.time = Date.now();
  231.  
  232.         }
  233.     }
  234. }
  235.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement