Skip to content

Instantly share code, notes, and snippets.

import { Type, typedArray } from '@thi.ng/api'
import { MemPool } from '@thi.ng/malloc'
import { Vec } from '@thi.ng/vectors'
import { computeNewData } from './buffers'
const { numSliceRows, numSliceColumns, resolution } = globalState.deref()
const poolSize = numSliceRows * numSliceColumns * (resolution + 3)
const POOL = new MemPool({ size: poolSize })
console.log('poolSize of', { poolSize })
@nkint
nkint / pil-on-the-fly.py
Last active May 7, 2021 09:54
Flask return numpy array on the fly
#!/usr/bin/env python3
from io import BytesIO
import numpy as np
import numpy.linalg as linalg
import scipy.interpolate as interpolate
from PIL import Image
from flask import Flask, send_file, escape, request
app = Flask(__name__)
@nkint
nkint / gist:6b9ecbfc85af06a787163dfb027c71a4
Created December 17, 2019 13:27
Circle as SVG path with A
function circlePath(cx=0, cy=0, r=10) {
// https://stackoverflow.com/a/10477334/433685
const startPointX = - r
const startPointY = 0
return `M ${cx} ${cy}
m ${startPointX}, ${startPointY}
a ${r},${r} 0 1,0 ${(r * 2)},0
@nkint
nkint / vec3-mat4.py
Created November 19, 2019 17:35
numpy - vec3 transformation mat4
import numpy as np
def cube_geometry(x, y, z):
xSize = x / 2
ySize = y / 2
zSize = z / 2
positions = np.array([
[-xSize, ySize, zSize], [xSize, ySize, zSize],
[-xSize, -ySize, zSize], [xSize, -ySize, zSize],
@nkint
nkint / use-script.ts
Created October 17, 2019 10:37
useScript
import { useState, useEffect } from 'react';
import { noop } from 'lodash';
/** original code from
* https://usehooks.com/useScript/
* https://stackoverflow.com/a/51242436/433685
* */
function isScriptLoaded(src: string) {
return document.querySelector('script[src="' + src + '"]') ? true : false;
@nkint
nkint / array-buffer-XMLHttpRequest.ts
Created September 28, 2019 14:45
Load array buffer via XMLHttpRequest, the old good way
function ab2str(buf: any) {
return Buffer.from(buf).toString("utf8");
}
console.log("hello");
var oReq = new XMLHttpRequest();
console.log(oReq);
oReq.addEventListener("load", reqListener);
oReq.open("GET", "./test.env");
oReq.responseType = "arraybuffer";
@nkint
nkint / a-test.ts
Last active August 19, 2019 19:08
1566240473 shader ast, broken test
import { clearDOM } from '@thi.ng/hdom'
import { Vec } from '@thi.ng/vectors'
import { buildSketch3d } from './sketch-skelton'
import { adaptDPI, CanvasHandlers } from '@thi.ng/hdom-components'
import { compileModel, draw, ModelSpec, shader, quad } from '@thi.ng/webgl'
import {
defMain,
assign,
FLOAT0,
FLOAT1,
@nkint
nkint / WIP.ts
Last active July 15, 2019 15:00
add raf stream
import * as tx from "@thi.ng/transducers";
import { clearDOM } from "@thi.ng/hdom";
import {
stream,
Stream,
sync,
fromRAF,
sidechainToggle
} from "@thi.ng/rstream";
import { updateDOM } from "@thi.ng/transducers-hdom";
@nkint
nkint / gist:0436719e2c6cae01e9cd27009cf5e884
Last active May 15, 2019 22:32
Quantum Harmonic Oscillator Animation
// use typescript
// use math.js
import math from "mathjs";
// a
// a1 a2 b c d
// (2^n*n!)^(-1/2) * Pi^(-1/4) * Exp[-x^2/2] * HermiteH[n, x];
function psi(n: number, x: number) {
@nkint
nkint / random-point-spike.ts
Created March 7, 2019 12:33
random points in a circle with mbostock and umbrella
import { renderOnce, clearDOM } from "@thi.ng/hdom";
import * as svg from "@thi.ng/hiccup-svg";
import * as tx from "@thi.ng/transducers";
import * as isec from "@thi.ng/geom-isec";
import { add2, subN2 } from "@thi.ng/vectors";
import { poissonDiscSampler } from "./poisson-disc-sampler";
const width = 600;
const height = 500;