Skip to content

Instantly share code, notes, and snippets.

View fi-tomek-augustyn's full-sized avatar

Tomek Augustyn fi-tomek-augustyn

View GitHub Profile
@fi-tomek-augustyn
fi-tomek-augustyn / gist:1999647
Created March 8, 2012 08:25
Tween.js example
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,
@fi-tomek-augustyn
fi-tomek-augustyn / gist:3972674
Created October 29, 2012 09:51
Transparent canvas fader
/**
* 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) {
@fi-tomek-augustyn
fi-tomek-augustyn / gist:3973048
Last active October 12, 2015 04:48
Offscreen canvas buffer example
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,
@fi-tomek-augustyn
fi-tomek-augustyn / Touch mapping
Last active December 10, 2015 22:28
Mapping touch points to rings on stage.
/**
* 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;
@fi-tomek-augustyn
fi-tomek-augustyn / gist:4692676
Last active December 12, 2015 01:38
Gesture detection example: Identifying global events
<!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;
@fi-tomek-augustyn
fi-tomek-augustyn / gist:4706145
Last active December 12, 2015 03:19
Gesture detection: Identifying global events
// 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);
@fi-tomek-augustyn
fi-tomek-augustyn / gist:4706155
Last active December 12, 2015 03:19
Gesture detection: Implementing Swipe, Pinch/Stretch and Rotate gestures
// 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