Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created July 10, 2025 23:48
Show Gist options
  • Save luizbills/e14689eb02e36cfab10ffb813a5df3aa to your computer and use it in GitHub Desktop.
Save luizbills/e14689eb02e36cfab10ffb813a5df3aa to your computer and use it in GitHub Desktop.
How to detect "swipe" gesture in Litecanvas
litecanvas();
const taps = new Map()
const actor = {}
function init() {
actor.x = W/2
actor.y = H/2
// on "swipe" move our actor
listen('swipe', (angle, len) => {
actor.x += len/2 * cos(angle)
actor.y += len/2 * sin(angle)
})
}
function draw() {
cls(0)
circfill(actor.x, actor.y, 64, 4)
}
function tap(x, y, id) {
// store the initial touch/click
taps.set(id, {x, y})
}
function untap(x, y, id) {
const from = taps.get(id)
taps.delete(id)
const angle = atan2(y - from.y, x - from.x);
const length = hypot(x - from.x, y - from.y);
emit('swipe', angle, length)
}
@luizbills
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment