Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Gordon gordonnl

View GitHub Profile
@gordonnl
gordonnl / Serve.js
Created May 19, 2020
Node development server
View Serve.js
// Based on https://github.com/lukejacksonn/servor
// For direct use
// node server ${process.cwd()} 8080 --debug
// node server ${process.cwd()}
const args = process.argv.slice(2).filter((x) => x.indexOf('-') !== 0);
const root = args[0];
const port = args[1];
const debug = ~process.argv.indexOf('--debug') || ~process.argv.indexOf('-d');
View raytrace_background.fs
// Author: Nathan Gordon
// Title: Raytrace Background for http://patriciogonzalezvivo.github.io/glslEditor/
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
@gordonnl
gordonnl / alchemy_AO
Created Nov 26, 2014
Alchemy AO Shader
View alchemy_AO
uniform sampler2D depths;
uniform sampler2D wc_normals;
uniform sampler2D random_texture;
uniform vec3 wc_camera_eye_position;
uniform floatz_far;
uniform vec2 tc_window;
uniform mat4 projection_matrix;
@gordonnl
gordonnl / hitTest.js
Last active Feb 4, 2021
Hit test in threejs for skinnedMesh using RTT
View hitTest.js
/*
*
* Render current frame and check pixel
* transparency beneath mouse position.
* Threejs required.
*
*/
var gl = renderer.context;
var rtTexture = new THREE.WebGLRenderTarget(WIDTH, HEIGHT, {minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat});
@gordonnl
gordonnl / textToPages.js
Last active Aug 29, 2015
Return pages of text based on available space
View textToPages.js
/*
*
* Use:
* var textPages = textToPages(myElement)
* returns array of strings.
*
*/
var textToPages = function(element) {
var pages = [];
@gordonnl
gordonnl / dragZoom.js
Created Oct 6, 2014
Drag and zoom controls with touch support.
View dragZoom.js
// Requires jquery and detectizr (checks classes of 'touch', 'firefox' and 'ie' on the html element)
var dragZoom = (function() {
// The container - normally styled to be the size of the page with overflow hidden.
var _cont = $('.container');
// The child of container, who is going to scale and move.
var _content = $('.content');
// Edit this to set max scale.
@gordonnl
gordonnl / inactive.js
Last active Aug 29, 2015
Pause Inactive Tab Using visibilitychange
View inactive.js
var forced = false;
var pauseWhileInactive = function() {
switch (document.visibilityState) {
case 'hidden' :
if (!sfx.volume.value) return;
forced = sfx.volume.value;
sfx.volume.value = 0;
break;
case 'visible' :
if (!forced) return;