Skip to content

Instantly share code, notes, and snippets.

//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 / 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 / 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 / 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 / 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 / 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 / PRNG
Last active February 6, 2020 08:32
Mersenne Twister: a good Pseudo Random Number Generator ( PRNG )
/*
from : http://en.wikipedia.org/wiki/Mersenne_twister
*/
let MT
let index
class PRNG {
static setSeed(seed) {
// Create a length 624 array to store the state of the generator
MT = new Uint32Array(624)
index = 0
/**
original code https://gist.github.com/Dan-Piker/f7d790b3967d41bff8b0291f4cf7bd9e
need to declare the following:
uniform vec3 origin;
uniform float p;
uniform float q;
uniform float t;
*/
@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 / Instances.js
Last active February 24, 2021 14:44
create InstancedGeometries from GLTF
import {
BufferAttribute,
Group,
InstancedBufferAttribute,
InstancedBufferGeometry,
Mesh,
MeshStandardMaterial,
Vector3,
} from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";