Skip to content

Instantly share code, notes, and snippets.

@nicoptere
nicoptere / convert.jsx
Last active December 19, 2023 13:39
converts after effects layers' keyframes to JSON and saves file on hard drive.
//JSON object
"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(t){return 10>t?"0"+t:t}function this_value(){return this.valueOf()}function quote(t){return rx_escapable.lastIndex=0,rx_escapable.test(t)?'"'+t.replace(rx_escapable,function(t){var e=meta[t];return"string"==typeof e?e:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+t+'"'}function str(t,e){var r,n,o,u,f,a=gap,i=e[t];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(t)),"function"==typeof rep&&(i=rep.call(e,t,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?i+"":"null";case"boolean":case"null":return i+"";case"object":if(!i)return"null";if(gap+=indent,f=[],"[object Array]"===Object.prototype.toString.apply(i)){for(u=i.length,r=0;u>r;r+=1)f[r]=str(r,i)||"null";return o=0===f.length?"[]":gap?"[\n"+gap+f.join(",\n"+gap)+"\n"+a+"]":"["+f.join(",")+"]",gap=a,o}if(rep&&"object"==typeof rep)for(u=rep.length,r=0;u>r;r+=1)"string"==typeof rep[r]&&(n=rep[r],o=str(n,i),o&&f.push
@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 / MercatorPlane.js
Last active September 2, 2020 13:01
THREE.js object that converts equirectangular (or spherical) projection to mercator projection
var MercatorPlane = function()
{
// create the material
var vs = "varying vec2 vUv;\nvoid main() {\n vUv = uv;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
var fs = "uniform sampler2D map;\nvarying vec2 vUv;\n void main() {\nvec4 color = texture2D( map, vUv );\ngl_FragColor = color;\n}";
var material = new THREE.ShaderMaterial({
uniforms: {
map: { type: "t", value: null }
@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 / ScaleX
Created June 7, 2015 09:59
performs a scale2x and scale3x operation on a HTML canvas
/*
JavaScript port of the following algorithm : http://scale2x.sourceforge.net/algorithm.html
*/
var scaleX = ( function( exports )
{
function getPixel32( data, x,y,w )
@nicoptere
nicoptere / gist:9838755b90c10d740054
Created May 2, 2015 14:11
periodic noise by Iñigo Quilez from ShaderToy
float hash( float n )
{
return fract(sin(n)*43758.5453);
}
float noise( vec3 x )
{
// The noise function returns a value in the range -1.0f -> 1.0f
vec3 p = floor(x);
@nicoptere
nicoptere / essentials.js
Last active March 24, 2018 12:11
essentials
<style>
html, body{
width:100%;
height:100%;
overflow: hidden;
top:0;
left:0;
margin:0;
padding:0;
}
@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 / 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 / canvas noise
Created January 21, 2015 13:15
noise function for canvas
/**
* creates a noise on the specified 2d context's canvas
* @ctx a 2d context
* @rgba color code specifies which channels are affected (default = 0 )
* @min noise lower bound ( >= 0 )
* @max noise upper bound ( <= 0xFF )
* */
function noise( ctx, rgba, min, max )
{