Skip to content

Instantly share code, notes, and snippets.

@hapticdata
hapticdata / animator.js
Created March 29, 2012 15:50
simplified animation using requestAnimationFrame with onComplete, stop and resume
/**
* animator factory for creating requestAnimationFrame callbacks
* and simplifying their cancellation. Includes Erik Moller polyfill
* @author Kyle Phillips
* @example
* animator(function(){
* //do this every time
* if(Math.random() > 0.9){
* this.complete();
* }
@hapticdata
hapticdata / watch-less.js
Created August 10, 2012 01:14
Watches all .less files and renders css with every change
#!/usr/bin/env node
/**
* Watches all project .less files,
* automatically renders css with every change
* usage: $watch-less ~/Sites/myProject1 ~/Sites/myProject2
*/
var less = require('less'),
@hapticdata
hapticdata / bubbled-console.js
Created September 6, 2012 02:32
bubble console methods from nested iframes into root window.console
//##console.log bubble for nested iframes
//##by [Kyle Phillips](http://haptic-data.com)
//find each iframe recursively and bubble its logs up to the current window.console
(function( d, w ){
function bubble( doc, win, msg ){
Array.prototype.forEach.call(doc.getElementsByTagName('iframe'), function( frame ){
if( !sameOrigin(frame.src) || !frame.contentWindow || !frame.contentWindow.console ){
w.console.log('console of iframe ', frame.src, ' is unreachable');
return;
}
@hapticdata
hapticdata / glsl.js
Created September 6, 2012 15:43
minimal AMD module directly wrapping webgl shaders
//A minimal wrapper around WebGL Shaders
//takes the vertexShader and fragmentShader as plain-text
//**basic use:**
//
// shaderProgram = glsl( gl )
// .createProgram(vertexShader, fragmentShader)
// .attributes({
// "vertexPositionAttribute" : 'aVertexPosition',
// 'vertexColorAttribute' : 'aVertexColor'
// })
@hapticdata
hapticdata / cssColors.js
Created October 29, 2012 02:20
RGB values for every X11 Color name in CSS
//RGB values for every X11 Color Name
//http://en.wikipedia.org/wiki/Web_colors
//author Kyle Phillips
var cssColors = {
indianred: [205, 92, 92],
lightcoral: [240, 128, 128],
salmon: [250, 128, 114],
darksalmon: [233, 150, 122],
lightsalmon: [255, 160, 122],
red: [255, 0, 0],
@hapticdata
hapticdata / plax.js
Last active December 10, 2015 13:08
starting point for binding an event (such as scroll) with various properties
/*
example:
new ParallaxSprite({
el: $('#element'),
watch: {
fn: function(){ return $(window).scrollTop(); },
from: 0,
to: 1000
},
tween: {
@hapticdata
hapticdata / toxiBufferGeometry.js
Created January 17, 2013 05:06
convert a toxiclibs.js trianglemesh into a three.js BufferGeometry, needs testing
define(function( require ){
var THREE = require('three');
/**
* take a toxiclibs.js mesh and turn it into a THREE.BufferGeometry
* @param {toxi.geom.mesh.TriangleMesh} mesh
* @type {THREE.BufferGeometry}
*/
return function( mesh ){
var geometry = new THREE.BufferGeometry();
//3 points per face, 3 axis per point
@hapticdata
hapticdata / Gruntfile.js
Created October 15, 2013 22:25
Read all of the grunt tasks out of your devDependencies and load them
//load all of the Grunt NPM Tasks out of the package.json
Object.keys(require('./package.json').devDependencies).forEach(function(dep){
if( dep.match(/grunt-/) ){
grunt.loadNpmTasks(dep);
}
});
@hapticdata
hapticdata / quickScene.js
Created October 29, 2013 23:28
A quick + consistent way to setup a three.js scene
define([
'three'
], function( THREE ){
/**
* quickly set up all of the basics of a THREE.js canvas
* @param {Object} [app] the settings for the app
* @param {Number} [app.width]
* @param {Number} [app.height]
* @param {Number} [app.fov]
@hapticdata
hapticdata / debug-node
Last active August 29, 2015 13:56
easy node and node-global debugging. 2 functions for your .bashrc
# put these in your ~/.bashrc and start a new shell to receive these commands
# requires node-inspector, install: npm install -g node-inspector
# start node-inspector and debug node app
# example: debug-node --open app.js --port=3000
function debug-node () {
# start node-inspector as a background-process
node-inspector &
# grab last PID to kill process later
INSPECTOR_PID=$!