Skip to content

Instantly share code, notes, and snippets.

# GIMP 'Curves' settings
(time 0)
(linear no)
(channel value)
(curve
(curve-type smooth)
(n-points 17)
(points 34 0.000000 0.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 1.000000 1.000000)
(n-samples 256)
function prodf(xs, ys, f) {
const rv = [];
for (let i = 0; i < xs.length; i++) {
for (let j = 0; j < ys.length; j++) {
rv.push(f(xs[i], ys[j]));
}
}
return rv;
}
@jcreedcmu
jcreedcmu / imaginary-book-club.md
Created March 13, 2022 15:55
Imaginary Book Club

Welcome to imaginary book club! I hope everyone finished the reading this week. No? Fine, we'll just wing it. At least there's snacks.

There is a deck of cards. Each has a question on it. Play starts with a random player and proceeds in a circle, with each player drawing a card and answering the question. The first two are always:

  • What is the book's title?
  • What is the book's genre?
@jcreedcmu
jcreedcmu / dither.ts
Created February 8, 2022 23:16
Make a wibbly image
// for any integer coordinates x, y, returns a float in [0,1] which is
// interpreted as threshold a float-valued function should have to
// reach in order to make a bitmap pixel.
function odither(x: number, y: number): number {
return (x == 0 && y == 0
? 0
: ([0, 2, 3, 1][(y % 2) * 2 + (x % 2)] + dither(x >> 1, y >> 1)) / 4);
}
function dither(x: number, y: number): number {
@jcreedcmu
jcreedcmu / dither.ts
Created February 7, 2022 23:45
Generate a nice dithered circle
// for any integer coordinates x, y, returns a float in [0,1] which is
// interpreted as threshold a float-valued function should have to
// reach in order to make a bitmap pixel.
function dither(x: number, y: number): number {
return (x == 0 && y == 0
? 0
: ([0, 2, 3, 1][(y % 2) * 2 + (x % 2)] + dither(x >> 1, y >> 1)) / 4);
}
function tableau(edge: number, f: (x: number, y: number) => number): number[][] {
@jcreedcmu
jcreedcmu / dither.ts
Created February 7, 2022 23:16
Generate a PBM file full of dithering patterns
const SCALE = 3;
// return the nth dithering point in an 2ᵏ × 2ᵏ square
// n ∈ [0, 4ᵏ - 1]
type Point = { x: number, y: number };
function ksquare(k: number): Point[] {
if (k == 0)
return [{ x: 0, y: 0 }];
else {
const prev = ksquare(k - 1);
@jcreedcmu
jcreedcmu / kolmogorov.txt
Last active December 27, 2021 15:24
Kolmogorov problem on graphs
# Trying to think about a very modest generalization of the "Kolmogorov Puzzle" that
# dan piponi posted here: https://twitter.com/sigfpe/status/1474173467016589323
Consider a directed graph with vertices V and edges E. Loops and multiple edges are allowed.
All graphs we consider will have the same vertices, so we more or less identify a graph with
its set of edges.
For any graph G, we:
1) write G[x, y] for the set of edges from x to y in G.
@jcreedcmu
jcreedcmu / defaultWithTexture.ts
Created January 31, 2021 21:57
string diagram scene
import { MeshBuilder } from "@babylonjs/core";
import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";
import { Engine } from "@babylonjs/core/Engines/engine";
import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";
import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
import { Color3, Color4 } from "@babylonjs/core/Maths/math";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { RibbonBuilder } from "@babylonjs/core/Meshes/Builders/ribbonBuilder";
import { Mesh } from "@babylonjs/core/Meshes/mesh";
import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
@jcreedcmu
jcreedcmu / sexp-parse.ts
Created November 26, 2020 18:01
Parsing sexps in at the type level in typescript
// Parsing sexpressions and turning them into nested array types,
// using template literal types.
// Cons a head onto an array type, assuming TL is actually an array type
type Cons<H, TL> = TL extends any[] ? [H, ...TL] : unknown;
// Interpret type names as types
type Interpret<TOK extends string> =
TOK extends 'number' ? number :
TOK extends 'string' ? string :
@jcreedcmu
jcreedcmu / type-shenanigans.ts
Created November 25, 2020 23:36
Typescript Shenanigans
// type Unary = 'Z' | `S${Unary}`; // considered circular
// Can implement unary addition and multiplication with template literal types
type Plus<T extends string, U extends string> = T extends `S${infer X}` ? `S${Plus<X, U>}` : U;
type Times<T extends string, U extends string> = T extends `S${infer X}` ? Plus<U, Times<X, U>> : 'Z';
// Trying to do length-aware vectors as dependent types
module Attempt1 {
type Vector<T, LEN> = LEN extends `S${infer X}` ? [T, ...Vector<T, X>] : [];