This file contains hidden or 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
| const observer = new IntersectionObserver((entries) => { | |
| if (entries[0].isIntersecting == true) { | |
| fetchNextArticle(); | |
| } | |
| }, {threshold: 0}); | |
| const bottomOfPage = document.querySelect('#bottom-of-page'); | |
| observer.observe(bottomOfPage); |
This file contains hidden or 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
| canvas.addEventListener('pointerover', (e) => {e.preventDefault()}); | |
| canvas.addEventListener('pointerout', (e) => {e.preventDefault()}); | |
| canvas.addEventListener('pointerenter',(e) => {e.preventDefault()}); | |
| canvas.addEventListener('pointerleave',(e) => {e.preventDefault()}); | |
| canvas.addEventListener('mouseover', (e) => {e.preventDefault()}); | |
| canvas.addEventListener('mouseout', (e) => {e.preventDefault()}); | |
| canvas.addEventListener('mouseenter', (e) => {e.preventDefault()}); | |
| canvas.addEventListener('mouseleave', (e) => {e.preventDefault()}); |
This file contains hidden or 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
| canvas.addEventListener('pointerdown', (event) => { | |
| gestures.addFinger(event); | |
| gestures.sendInitialGesture(); | |
| event.preventDefault(); | |
| }; |
This file contains hidden or 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
| var initialDistance = Math.hypot(initialRise, initialRun); | |
| var latestDistance = Math.hypot(latestRise, latestRun); | |
| var deltaDistance = Math.abs(latestDistance - initialDistance); |
This file contains hidden or 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
| // initial metrics | |
| var initialRise = finger0.initial.y - finger1.initial.y; | |
| var initialRun = finger0.initial.x - finger1.initial.x; | |
| var initialTheta = Math.atan2(initialRise, initialRun); | |
| var initialAngle = 180 - (initialTheta * 180 / Math.PI); | |
| if (initialAngle < 0) | |
| initialAngle += 180; | |
| // latest metrics | |
| var latestRise = finger0.latest.y - finger1.latest.y; |
This file contains hidden or 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 file contains hidden or 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
| class FingerPointer { | |
| constructor(event) { | |
| this.pointerId = event.pointerId; | |
| this.pointerType = event.pointerType; | |
| this.epsilonX = event.width; | |
| this.epsilonY = event.height; | |
| this.initial = { | |
| x: event.offsetX, |
This file contains hidden or 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
| class Gestures { | |
| constructor(canvas) { | |
| this.canvas = canvas; | |
| this.fingerPointers = []; | |
| } | |
| // finger pointers appearing and disappearing | |
| addFinger(event) { ... } | |
| updateFinger(event) { ... } | |
| removeFinger(event) { ... } |
This file contains hidden or 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
| class InteractionHandler { | |
| constructor(canvas) { | |
| const gestures = new Gestures(canvas); | |
| canvas.addEventListener('pointerdown', (event) => { | |
| gestures.addFinger(event); | |
| gestures.sendInitialGesture(); | |
| }; | |
| canvas.addEventListener('pointermove', (event) => { | |
| gestures.updateFinger(event); |
This file contains hidden or 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
| import ContactTracing from './contact-tracing.class.js'; | |
| // Instantiate with the mobile device's 32-byte private key | |
| const ct = new ContactTracing('a1b2c3d411jj99kk55gg66hhz0y9x8w7'); | |
| // Test data for Medium article "Contact Tracing with Android/iPhone" | |
| const encounters = [ | |
| {person: 'Uber driver', ts: 'May 15, 2020 16:21:00'}, | |
| {person: 'Nearby shopper', ts: 'May 15, 2020 16:51:00'}, | |
| {person: 'Stranger', ts: 'May 16, 2020 17:06:00'}, |