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 / 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 ){
@nicoptere
nicoptere / remove small paths in illustrator
Last active May 30, 2018 20:59
this will remove illustrator paths under a given length ( to clean up smaller paths basically )
#target illustrator
var document = app.activeDocument;
var maxLength = prompt ("maximum length of a path", 10, "destroy them with lasers!");
for (i=0 ; i< document.pathItems.length; i++)
{
var ipath = document.pathItems[i]
if( ipath.hidden == true )continue;
var l = 0;
for( var j = 0; j < ipath.pathPoints.length - 1; j++ ){
var p0 = ipath.pathPoints[j].anchor;
@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 )
{
@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;
}
//from https://math.stackexchange.com/questions/296794/finding-the-transform-matrix-from-4-projected-points-with-javascript/339033#339033
// and http://jsfiddle.net/dFrHS/1/
function adj(m) { // Compute the adjugate of m
return [
m[4]*m[8]-m[5]*m[7], m[2]*m[7]-m[1]*m[8], m[1]*m[5]-m[2]*m[4],
m[5]*m[6]-m[3]*m[8], m[0]*m[8]-m[2]*m[6], m[2]*m[3]-m[0]*m[5],
m[3]*m[7]-m[4]*m[6], m[1]*m[6]-m[0]*m[7], m[0]*m[4]-m[1]*m[3]
];
}
@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;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>postmortem</title>
<style>
html, body{
width:100%;
height:100%;
overflow: hidden;
@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;
@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++)
{