Skip to content

Instantly share code, notes, and snippets.

@ianthehenry
ianthehenry / hot-air-balloon.janet
Last active September 9, 2022 15:36
Bauble: hot air balloon
(def bottom (+ -100 -50))
(defn quantize [x y]
(x * y | round / y))
(def envelope
(sphere 100
| union :r 50 (cylinder :y 25 50 | move :y -100)
| scale
:y (ss p.y bottom 100 1 0.80)
@ianthehenry
ianthehenry / unquasiquote.md
Last active July 12, 2023 06:48
Lisp without quasiquote

I think that you can write a reasonable lisp entirely without quasiquote.

There are three pieces that you need:

  1. Functions can appear literally in the AST (à la Janet and Common Lisp)
  2. Macros can appear literally in the AST, and specifically they have to have a different runtime representation than functions
  3. Special forms are their own thing explained below

Basically when you're writing Janet-style macros, you can/should unquote pretty much every symbol in order to do lexical lookup at the macro-definition at compile time, rather than the call-site at runtime:

@ianthehenry
ianthehenry / synth.ino
Created May 15, 2023 02:34
Binary synthesizer
#include "MIDIUSB.h"
#define STATUS_LED 13
int pressed[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int intervals[8] = {1, 2, 4, 8, -1, -2, -4, -8};
int rows[2] = {5, 6};
int cols[4] = {9, 10, 11, 12};
int note = 0;
@ianthehenry
ianthehenry / turtle.janet
Last active July 12, 2023 07:00
Bauble: animated turtle
(def eye-target [100 20 40])
(def eye-shapes
(sphere 5
| move [8 10 10]
| mirror :z))
(def eyes
(eye-shapes
| color (c + 0.5)
$ hyperfine --warmup 10 --shell=none 'zig-out/cyber/cyber test/bench/fib/fib.cy' 'janet test/bench/fib/fib.janet' 'lua test/bench/fib/fib.lua' 'luajit test/bench/fib/fib.lua'
Benchmark 1: zig-out/cyber/cyber test/bench/fib/fib.cy
Time (mean ± σ): 54.6 ms ± 1.4 ms [User: 53.1 ms, System: 1.1 ms]
Range (min … max): 52.8 ms … 59.7 ms 55 runs
Benchmark 2: janet test/bench/fib/fib.janet
Time (mean ± σ): 191.3 ms ± 5.4 ms [User: 188.5 ms, System: 1.6 ms]
Range (min … max): 184.1 ms … 203.6 ms 16 runs
Benchmark 3: lua test/bench/fib/fib.lua
#include "MIDIUSB.h"
#define STATUS_LED 13
int pressed[72] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int changed[72] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
#define ROW_COUNT 9
#define COL_COUNT 8
int rows[ROW_COUNT] = {5, 6, 9, 10, 11, 12, 20, 19, 18};
int cols[COL_COUNT] = {21, 22, 23, 15, 16, 14, 0, 1};
@ianthehenry
ianthehenry / kinopio.bauble
Created October 1, 2024 19:17
kinopio.bauble
(box [50 37 50] :r (ss p.y 50 -70 50 0)
| morph (cylinder y 50 50 :r 26)
| move y (ss p.y -50 0 3 0 * (cos (p.x / 12) + (cos (p.z / 12))))
| scale [1 0 1 * (ss p.y -20 -50 0 -0.1 * (cos (p.x / 12) + (cos (p.z / 12)))) + 1]
| shade cyan :g 10
| union (capsule z 13 6.2 | move x 49.1 z 14.5 y 3 | shade white | mirror z)
(cylinder x 2.7 0 | expand 2.1 | move x 55.02 y 2 z 20.2 | shade black| mirror z | move z (sin t * -1))
(torus x 5 2 | move [50.6 -14.9 0] | elongate z (4.3 + (2 * sin (t / 2))) | shade (hsv (5.49 / 6) 0.63 1))
| with-lights (light/ambient 0.75 :brightness (mix 0.5 1 (occlusion :dist 20)))
(light/directional 0.25 [-1 -1 0 | normalize] 100 :shadow 0.67)