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
function init() { | |
// Create and populate the Array of Objects | |
for (var i = 0; i < numPoints; i++) { | |
var point = addDOMPoint(i); | |
pointsY[i] = { | |
// index | |
i: i, | |
x: i * xSpacing, | |
y: 400, |
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
/** | |
* Fade transparent canvas using 'destination-out' mode. | |
* To avoid visible trails call | |
* fadeCanvas(canvas, 0.4, 'source-over'); | |
* | |
* @param {element} canvas Reference to a Canvas DOM element | |
* @param {number} alpha Alpha percentage of how much to fade | |
* @param {string} mode Fading mode | |
*/ | |
function fadeCanvas(canvas, alpha, mode) { |
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
var buffers = []; | |
drawLightBlob(ctx, 255, 0, 0, 300, 300, 100); | |
/** | |
* Draw a blob of light (with offscreen canvas buffering) | |
*/ | |
function drawLightBlob(ctx, r, g, b, x, y, radius) { | |
var buffer, | |
bufferCanvas, |
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
/** | |
* Map the ring nearest to touch point | |
* @param {number} id touch point id | |
* @param {number} x touch point x | |
* @param {number} y touch point y | |
*/ | |
function mapNearestRing(id, x, y) { | |
var minDistance = 1000000; | |
var nearestRing = null; |
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
<!doctype html> | |
<html> | |
<head> | |
<title>Gesture detection example</title> | |
<meta http-equiv="X-UA-Compatible" content="IE=Edge"> | |
<style> | |
.gestureSurface { | |
width: 640px; | |
height: 480px; | |
background-color: red; |
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
// Add event listeners | |
surface.addEventListener('MSPointerDown', function(event) { | |
// Add pointer to track | |
msGesture.addPointer(event.pointerId); | |
}); | |
// Reset when gesture starts | |
surface.addEventListener('MSGestureStart', resetGesture); | |
// Try to detect when gesture changes | |
surface.addEventListener('MSGestureChange', detectGesture); |
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
// Define constant values | |
var MIN_ROTATION = 20; | |
var MIN_SCALE = .3; | |
var MIN_SWIPE_DISTANCE = 50; | |
// Define variables | |
var rotation, scale, recognized, translationX, translationY; | |
/** | |
* Reset gesture |