Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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;
@nicoptere
nicoptere / toOBJ
Created April 14, 2017 15:06
converts a THREE.geometry to OBJ
var str = "# object mesh \n";
g.toIndexed();
var vs = g.getAttribute("position").array;
var ind = g.getIndex().array;
var precision = 6;
for( var i = 0 ; i < vs.length; i+=3 ){