Skip to content

Instantly share code, notes, and snippets.

View snorpey's full-sized avatar

georg fischer snorpey

View GitHub Profile
@snorpey
snorpey / load-file.js
Last active August 29, 2015 14:00
AMD module for loading a file asynchronously. It also stores the file in the browsers local storage for quicker access. I mostly use it for loading GLSL shader files
/*global define*/
/*
AMD module for loading files asynchronously. It also stores the contents of the files
in the browsers local storage for quicker access. I mostly use it for loading GLSL
shader files. Note: This has not been tested extensively, so use with caution.
MIT License
*/
define(
function()
{
@snorpey
snorpey / serialize-url.js
Last active August 29, 2015 13:57
converts an object to an url parameter string
/*global define*/
define(
function ()
{
// serializeURL({foo:'bar',one:'two'}) => '?foo=bar&one=two'
// serializeURL({foo:'bar',one:'two'}, 'prefix') => '?prefix[foo]=bar&prefix[one]=two'
function serializeURL( obj, prefix )
{
var str = [ ];
@snorpey
snorpey / get-transition-duration.js
Last active December 26, 2015 23:28
Get the CSS transition duration of a DOM element, cross-browser. without jQuery.
// based on http://stackoverflow.com/a/13008597
function getTransitionDuration ( element, with_delay )
{
var prefixes = ' webkit moz ms o khtml'.split( ' ' );
var result = 0;
var duration, delay, prefix;
for ( var i = 0; i < prefixes.length; i++ )
{
prefix = prefixes[i] + '-';
@snorpey
snorpey / convert.sh
Created September 13, 2013 12:00
batch convert x3db files into vrml files
# this converts x3db files into vrml files
# a few notes:
# 1. run this in a unix-like shell (like the one that comes with git) on windows
# 2. aopt.exe comes is bundled with the instant reality player ( http://www.instantreality.org/downloads/ )
ls | grep ".x3db" | xargs -i /C/Program\ Files/Instant\ Reality/bin/aopt.exe -i {} -v "{}".wrl
@snorpey
snorpey / cmd.sh
Created September 11, 2013 15:21
batch convert wrl files to stl
# this command uses the 3d mesh converter to convert wrl files to stl files.
# http://www.cs.princeton.edu/~min/meshconv/
ls | grep ".wrl" | xargs -i meshconv.exe {} -c stl
@snorpey
snorpey / greyscale-imagedata.js
Created July 13, 2013 10:24
convert an imagedata object (from an html5 canvas) to greyscale
/*global define*/
define(
function()
{
function greyscaleImageData( image_data )
{
var data = image_data.data;
var len = image_data.data.length;
var i = 0;
var brightness;
@snorpey
snorpey / brightness-rgba.js
Last active December 19, 2015 17:19
quickly calculate the brightness of an rgba color in javascript (not accurate but fast)
/*global define*/
define(
function()
{
function brightness( color )
{
// (R+R+B+G+G+G)/6
return ( color[0] + color[0] + color[1] + color[2] + color[2] + color[2] ) / 6;
}
@snorpey
snorpey / blend-rgba.js
Created July 13, 2013 10:20
blend two rgba colors in javascript.
/*global define*/
define(
function()
{
var result = { r: 0, g: 0, b: 0, a: 0 };
var red_1, red_2, red_result;
var green_1, green_2, green_result;
var blue_1, blue_2, blue_result;
var alpha_1, alpha_2, alpha_result;
var type = 'array';
@snorpey
snorpey / average-rgba.js
Created July 13, 2013 10:18
get average color of an imagedata object (from an html5 canvas) in javascript
/*global define*/
define(
function()
{
var i;
var len;
var multiplicator = 20;
var count;
var rgba;
@snorpey
snorpey / bresenham.js
Created July 13, 2013 10:15
a javascript implementation of bresenham’s line algorythm ( https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm ) as an amd module.
/*global define*/
define(
function()
{
var result;
var delta_x;
var delta_y;
var step_x;
var step_y;
var sign_dx;