Skip to content

Instantly share code, notes, and snippets.

@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 / imageProxy.php
Last active December 27, 2023 17:30
basic PHP image proxy (that works ... )
<?php
$url = "";
if( isset( $_GET['url'] ) )
{
$url = $_GET[ 'url' ];
}
else
{
@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 / THREE.js lon_lat_to_cartesian
Last active January 16, 2023 09:56
methods to convert longitude / latitude to XYZ and back + utility polygon contains point for THREE.js
/**
* converts a XYZ vector3 to longitude latitude (Direct Polar)
* @param lng longitude
* @param lat latitude
* @param vector3 optional output vector3
* @returns a unit vector of the 3d position
*/
function lonLatToVector3( lng, lat, out )
{
out = out || new THREE.Vector3();
import os
import cv2
import numpy as np
folder = "./cat/"
files = os.listdir(folder)
files.sort( )
dst = np.ones( (143,143), np.float )
for i, (f) in enumerate( files ):
img = cv2.imread(folder + f, cv2.IMREAD_UNCHANGED)
img = cv2.cvtColor( img, cv2.COLOR_BGR2GRAY )
@nicoptere
nicoptere / atlas.py
Last active October 21, 2021 07:32
atlas maker + rgb packer
import os
import argparse
import cv2
import numpy as np
from tqdm import tqdm
from math import ceil, sqrt
def atlasFromFolder( name, src, dst, tile, packChannels, quality ):
if src[:-1] != "/":
@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";
@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 }
/**
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 / 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