Skip to content

Instantly share code, notes, and snippets.

@tdhooper
tdhooper / merge.py
Last active September 13, 2022 12:03
from wand.image import Image, COMPOSITE_OPERATORS
from wand.drawing import Drawing
from wand.display import display
import sys
import os
import re
import glob
import pprint
@tdhooper
tdhooper / move.lsp
Created June 21, 2020 12:57
glisp move
(background "darkblue")
(def pts (point-cloud [119 139.203125] [216 53]))
(def pts2 (map (fn-sugar(vec2/+ % [133 91.203125])) pts))
(style (fill "#FCC")
(map #(circle % 23) pts2)
)
@tdhooper
tdhooper / voronoi.lsp
Created June 18, 2020 14:27
glisp voronoi
(def diagrams [
(point-cloud [812 334.203125] [463 886.203125] [301 588.203125] [451 316.203125] [627 599.203125] [994 598.203125] [807 880.203125] [1180 328.203125] [1317 597.203125] [1164 889.203125] [643 59.203125] [990 61.203125] [994 1137.203125] [645 1140.203125])
(point-cloud [812 334.203125] [463 886.203125] [301 588.203125] [450 317.203125] [627 599.203125] [994 598.203125] [807 880.203125] [1180 328.203125] [1317 597.203125] [1164 889.203125] [643 59.203125] [990 61.203125] [994 1137.203125] [645 1140.203125] [714 459.203125] [903 458.203125] [809 593.203125])
(point-cloud [812 334.203125] [463 886.203125] [301 588.203125] [451 316.203125] [627 599.203125] [994 598.203125] [807 880.203125] [1180 328.203125] [1317 597.203125] [1164 889.203125] [643 59.203125] [990 61.203125] [994 1137.203125] [645 1140.203125] [719 458.203125] [903 465.203125] [809 593.203125] [946 528.203125] [856 529.203125] [901 595.203125])
(point-cloud [812 334.203125] [463 886.203125] [301 588.203125] [451 316.203125] [6
@tdhooper
tdhooper / perfectgif.py
Created April 9, 2020 21:48
Optimize a gif to a specific file size
#!/usr/bin/env python3
import sys
import os
import ffmpeg
from pygifsicle import optimize
frames_path = sys.argv[1]
output_name = sys.argv[2]
#!/bin/sh
# From http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
# Usage:
# ./makegif.sh inputframes output.gif
# where inputframes is a directory containing .png frames
# Change size here
filters="scale=640:-1:flags=lanczos"
@tdhooper
tdhooper / makemp4.sh
Last active August 17, 2021 17:29
ffmpeg instagram
#!/bin/sh
# usage: ./makemp4.sh export01 output01
frames=`mktemp -d`
for i in 1 2 3; do
for file in $1/*.png; do
filename=$(basename "$file")
cp "$file" "$frames/$i-$filename"
@tdhooper
tdhooper / vectorfield.js
Created December 13, 2019 14:59
Stellar magnetic field
const sub = (a, b) => [
a[0] - b[0],
a[1] - b[1],
];
const distance = (a, b) => Math.sqrt(
Math.pow(a[0] - b[0], 2) +
Math.pow(a[1] - b[1], 2)
);
#!/bin/sh
# From http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
# Usage:
# ./makegif.sh export01 output.gif
palette="/tmp/palette.png"
filters="scale=640:-1:flags=lanczos"
ffmpeg -r 60 -f rawvideo -pix_fmt bgra -s 1920x1080 -i - -threads 0 -preset veryslow -y -s 1920x1080 -color_primaries bt470bg -color_trc gamma28 -color_range jpeg -colorspace bt470bg -sws_flags lanczos+accurate_rnd+full_chroma_int+full_chroma_inp -pix_fmt yuv420p -crf 17 output.mp4
-color_primaries bt470bg -color_trc gamma28 -color_range jpeg -colorspace bt470bg
@tdhooper
tdhooper / faster-helix.glsl
Last active April 24, 2018 22:30
Faster helix distance
vec2 closestPointOnRepeatedLine(vec2 line, vec2 point){
// Angle of the line
float a = atan(line.x, line.y);
// Rotate space so we can easily repeat along
// one dimension
pR(point, -a);
// Repeat to create parallel lines at the corners