Skip to content

Instantly share code, notes, and snippets.

@jcreedcmu
jcreedcmu / collab.js
Created Nov 30, 2022
collabradoodle renderer
View collab.js
const W = 52;
const H = 30;
const MAX_ITER = 1000;
function iters(cr, ci) {
let zi = 0;
let zr = 0;
for (let i = 0; i < MAX_ITER; i++) {
[zr, zi] = [zr * zr - zi * zi + cr, 2 * zr * zi + ci];
if (zr * zr + zi * zi > 16.0) return i;
View gist:74ffc069723cf7622a043596cd4c2bc4
5403 Friendship Avenue.
Henry Wright Fisher loĝis ĉi tie en 1912.
Sr. Fisher naskiĝis en Youghal, Ireland, Januaro 31, 1861, la filo de
Abram kaj Sara (Wright) Fisher. Li alvenis al Usono je 1874, kaj post
dekkvar jaroj, ricevis diplomon pri mekanika inĝenierarto de la
universitato Cornell. Post diplomiĝo, li ligiĝis kun la entrepreno
Bergman & Co. kaj la C. & C. Motor Company, kaj poste eniris la
servicon de Standard Underground Cable Company, fariĝinte ĝia
@jcreedcmu
jcreedcmu / delimiters.txt
Created Jun 20, 2022
unicode left/right pairs
View delimiters.txt
# # I ran the following perl script on the file
# # https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt:
#
# #!/usr/bin/perl
#
# use charnames();
# use utf8;
# use open qw( :std :encoding(UTF-8) );
# use File::Basename;
#
View penrose.ts
import { Point, rot90, rotate, vdiv, vdot, vplus, vscale } from './point';
const NARROW_COLOR = '#ffffff';
const WIDE_COLOR = '#7777ff';
const BG_COLOR = WIDE_COLOR; // '#dff';
const LINE_WIDTH = 0.25;
const width = 1024;
const height = 768;
const OFF_MIN = -9;
View curves
# 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)
View 4ct.js
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;
}
View imaginary-book-club.md

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 Feb 8, 2022
Make a wibbly image
View dither.ts
// 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 Feb 7, 2022
Generate a nice dithered circle
View dither.ts
// 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 Feb 7, 2022
Generate a PBM file full of dithering patterns
View dither.ts
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);