Skip to content

Instantly share code, notes, and snippets.

🎉
Celebrating 20 years of building open source tools

Karsten Schmidt postspectacular

🎉
Celebrating 20 years of building open source tools
Block or report user

Report or block postspectacular

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@postspectacular
postspectacular / 00-sigmoid-approx.ts
Last active Nov 2, 2019
Sigmoid versions (AssemblyScript)
View 00-sigmoid-approx.ts
// uses Math.exp() approximation from:
// https://www.musicdsp.org/en/latest/Other/222-fast-exp-approximations.html
// @ts-ignore: decorator
@inline
function fastexp9(x: f64): f64 {
// prettier-ignore
return (362880+x*(362880+x*(181440+x*(60480+x*(15120+x*(3024+x*(504+x*(72+x*(9+x)))))))))*2.75573192e-6;
}
@postspectacular
postspectacular / accessors.ts
Last active Oct 14, 2019
Super slow numeric property accessors - why is [0] / [1] access 110x slower than .x/.y?
View accessors.ts
import { bench } from "@thi.ng/bench";
import { map, range } from "@thi.ng/transducers";
export class Vec2 {
buf: Float32Array;
constructor(buf: ArrayBuffer, off: number) {
this.buf = new Float32Array(buf, off, 2);
}
View tokenizer.js
function tokenizeSexpr(src) {
let curr = "";
const scopes = [[]];
const $word = () => {
if (curr) {
scopes[scopes.length - 1].push(curr);
curr = "";
}
};
for(let i = 0; i < src.length; i++) {
View petecory.ts
import {
area,
centroid,
clipConvex,
convexHull,
points,
polygon,
rect,
scatter,
withAttribs
@postspectacular
postspectacular / hello-ast.js
Last active Jun 14, 2019
@thi.ng/shader-ast WIP codegen example w/ multiple output targets (GLSL & JS)
View hello-ast.js
// // // //
// ///// // //// // //// ///// //// ///// //////
// // ///// // ///// // // // // ////// // // //
// //// // // ///// // // ////// // ///// //// //
// // // // // // // // // // // // // //
// ///// // // ///// ///// //// // ///// ///// ///
//
// Head over to thi.ng/shader-ast for more details
const ast = require("@thi.ng/shader-ast");
View deform.vex
// deform code
vector4 planes[] = point(1, "planes", @id);
foreach(vector4 plane; planes) {
vector n = set(plane.x, plane.y, plane.z);
float d = dot(n, @P) + plane.w;
// check if point is "above" intersection plane
// since the plane normal always points away from each sphere's center
// this will select all points intersecting a neighbor sphere
if (d > 0) {
@postspectacular
postspectacular / sdf-svg-heatmap.ts
Last active Mar 15, 2019
Shroomania: SDF SVG heatmap
View sdf-svg-heatmap.ts
import { DisjointSet } from "@thi.ng/adjacency";
import { cosineColor, GRADIENTS } from "@thi.ng/color";
import { identity, partial } from "@thi.ng/compose";
import { serialize } from "@thi.ng/hiccup";
import { rect, svg, text } from "@thi.ng/hiccup-svg";
import { fitClamped, wrap } from "@thi.ng/math";
import { IRandom, Smush32 } from "@thi.ng/random";
import {
buildKernel2d,
comp,
@postspectacular
postspectacular / wolfram.js
Created Mar 10, 2019
Transducer based, branch-less 1D Wolfram automata (textmode)
View wolfram.js
const tx = require("@thi.ng/transducers");
const txb = require("@thi.ng/transducers-binary");
// ANSI clear screen esc seq
const CLEAR = "\x1b[2J\x1b[;H";
// CA dimensions
const WIDTH = 72;
const HEIGHT = 24;
@postspectacular
postspectacular / rulegen.ts
Last active Mar 4, 2018
@thi.ng/hiccup-css example to generate tachyons.css width & height rules incl. their media query versions
View rulegen.ts
import * as fs from "fs";
import * as css from "@thi.ng/hiccup-css";
const mediaQueries = [
[""],
["-ns", "--breakpoint-no-small"],
["-m", "--breakpoint-medium"],
["-l", "--breakpoint-large"]
];
View keybase.md

Keybase proof

I hereby claim:

  • I am postspectacular on github.
  • I am toxi (https://keybase.io/toxi) on keybase.
  • I have a public key ASChmJFjwANWhFE5SMqUl6TX65dPobiDLv4CtgE0WgIxIQo

To claim this, I am signing this object:

You can’t perform that action at this time.