Skip to content

Instantly share code, notes, and snippets.

@nicoptere
nicoptere / lol()
Last active Aug 29, 2015
lol() : improving the console.log through dynamic LULZ injection
View lol()
/**
* lol()
* improving the console.log through dynamic LULZ injection
*
* history
* - v0.0 RC - 2014-08-08 - 13h01 : initial release
* - v0.1 RC - 2014-08-08 - 13h29 : DogeScript support
*
* Licensed under WTFPL
*
@nicoptere
nicoptere / bitmasking
Created Oct 14, 2014
bit masking, basic operations
View bitmasking
/**
* checks if a value has a given bit set to 1
* @value the int / uint to test
* @mask the bits to check
**/
function bit_isset( value, mask )
{
return ( value & mask ) != 0;
}
@nicoptere
nicoptere / float triplets sorting method
Last active Aug 29, 2015
sorting triplets of floats in a buffer (vertices, indices, normals etc. ) using the QuickSort method.
View float triplets sorting method
/*
the quick sort method is described here :
http://antjanus.com/blog/web-development-tutorials/understanding-quicksort-js-native-implementation/
*/
function tripletSort( arr )
{
@nicoptere
nicoptere / log caller
Created Jan 28, 2015
tries to log the function caller
View log caller
var console = (window.console = window.console || {});
var original = console[ 'log' ];
console[ "log" ] = function()
{
var args = Array.prototype.slice.apply( arguments );
original.apply( console, args );
try
{
throw new Error();
}
@nicoptere
nicoptere / dijkstra
Created Mar 15, 2015
dijkstra algorithm ( brutal implementation )
View dijkstra
function dijkstra( graph_array, source, target)
{
//builds adjacency list
var vertices = [];
var neighbours = {};
graph_array.forEach( function( edge )
{
//store the vertex 0
@nicoptere
nicoptere / sortGauss.js
Created Aug 12, 2015
sorts an array by storing highest values in the "center"
View sortGauss.js
//sorts an array by storing highest values in the "center"
function sortGauss( array )
{
array.sort( function(a,b)
{
return a - b;
});
var a = [];
var b = [];
while( array.length > 0 )
@nicoptere
nicoptere / bresenham.js
Created Oct 20, 2015
bresenham circle / disc
View bresenham.js
function bresenhamCircle( cx,cy,r )
{
var x = 0,y = r,p;
ctx.fillRect( cx+x,cy-y, 1, 1 );
p=3-(2*r);
for(x=0;x<=y;x++)
{
@nicoptere
nicoptere / mixer
Created Jun 15, 2016
texture mixer
View mixer
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>MIXER</title>
<style>
head, body{
width:100%;
height:100%;
overflow: hidden;
View gist:abe6cabf590158c885ecce0768cee41c
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>postmortem</title>
<style>
html, body{
width:100%;
height:100%;
overflow: hidden;
View Object3D.js
/**
* Created by nico on 19/02/14.
*/
var Object3d = function( node, position, rotation )
{
this.node = node;
this.parent = null;