Created
February 21, 2021 03:43
-
-
Save joehonton/581c4a13ac2cf32b23f421fc25a28739 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
calculateLatest(event) { | |
this.latest.t = Date.now(); | |
this.latest.x = event.offsetX; | |
this.latest.y = event.offsetY; | |
// time difference | |
this.deltaT = this.latest.t - this.initial.t; | |
// distance traveled | |
this.deltaX = Math.abs(this.latest.x - this.initial.x); | |
this.deltaY = Math.abs(this.latest.y - this.initial.y); | |
this.deltaXY = Math.hypot(this.deltaX, this.deltaY); | |
// direction of movement | |
this.directionX = (this.latest.x - this.initial.x >= 0) ? | |
'right' : 'left'; | |
this.directionY = (this.latest.y - this.initial.y >= 0) ? | |
'down' : 'up'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment