Skip to content

Instantly share code, notes, and snippets.

@nicoptere
nicoptere / lol()
Last active August 29, 2015 14:05
lol() : improving the console.log through dynamic LULZ injection
/**
* 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 October 14, 2014 16:00
bit masking, basic operations
/**
* 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 August 29, 2015 14:08
sorting triplets of floats in a buffer (vertices, indices, normals etc. ) using the QuickSort 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 January 28, 2015 14:04
tries to log the function 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 March 15, 2015 10:33
dijkstra algorithm ( brutal implementation )
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 August 12, 2015 06:17
sorts an array by storing highest values in the "center"
//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 October 20, 2015 10:52
bresenham circle / disc
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 June 15, 2016 09:12
texture mixer
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>MIXER</title>
<style>
head, body{
width:100%;
height:100%;
overflow: hidden;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>postmortem</title>
<style>
html, body{
width:100%;
height:100%;
overflow: hidden;
@nicoptere
nicoptere / Object3D.js
Created July 5, 2016 09:33
object3d CSS
/**
* Created by nico on 19/02/14.
*/
var Object3d = function( node, position, rotation )
{
this.node = node;
this.parent = null;