Skip to content

Instantly share code, notes, and snippets.


Max Cahill 1bardesign

View GitHub Profile
1bardesign / oklab_snippet.glsl
Last active Apr 30, 2021
oklab to rgb and back for love2d glsl - see - todo: polar coordinate mode
View oklab_snippet.glsl
vec3 oklab_to_rgb(vec3 lab) {
float L = lab.x;
float a = lab.y;
float b = lab.z;
float l_ = L + 0.3963377774 * a + 0.2158037573 * b;
float m_ = L - 0.1055613458 * a - 0.0638541728 * b;
float s_ = L - 0.0894841775 * a - 1.2914855480 * b;
1bardesign / conf.lua
Last active Feb 23, 2021
A little self-contained pomodoro timer for love2d
View conf.lua
function love.conf(t)
t.window.width, t.window.height = 200, 60
t.window.x, t.window.y = 10, 10
t.window.borderless = true
t.window.title = "Pomodoro!"
1bardesign / texture_utils.lua
Last active Oct 1, 2020
texture utilities including various downsamples, dilation, and blurring
View texture_utils.lua
--texture utilities
--todo: clean up and include in
Copyright (c) 2020 Max Cahill
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
1bardesign / shader_try_send.lua
Created Sep 3, 2020
try to send a uniform to a shader without getting blocking errors when it's been optimised away
View shader_try_send.lua
try to send a uniform to a shader
prints a warning once for the lifetime of the shader for missing uniforms
otherwise succeeds or fails silently
local _warned = setmetatable({}, {__mode = "k"})
local function _warn(s, u)
local already_warned = _warned[s]
if not already_warned then
1bardesign / metatable_example.lua
Created May 12, 2020
a heavily commented example of using metatables to implement class-like behaviour in lua
View metatable_example.lua
--define the example class table
local example_class = {}
--build the class metatable
--this is instructions to lua for what we want instances to do in certain circumstances = {
--we only really care about the index metamethod
--this one says that if something is missing in the table this metatable is set on
--to go look in the example_class table
__index = example_class,
1bardesign / matrix_utility.lua
Created Mar 30, 2020
Perspective projection and camera lookat functions for love2d
View matrix_utility.lua
matrix utility functions for love2d
expects vec3 from
return {
calculate_perspective = function(screen, fov, near, far, into)
--everything we need
local aspect = screen[1] / screen[2];
1bardesign / main.lua
Last active May 17, 2020
simplified hydraulic erosion on the gpu in love
View main.lua
Simplified hydraulic erosion on the gpu in love
Some instabilities here and there but was a fun evening project to tackle
For Matt, hope it helps!
1bardesign /
Last active Jun 2, 2020
Hopefully straightforward writeup on the design of my lua-side "ecs", which I should find a better name for.


  • Managed by systems, self-contained as much as possible
  • May have references to components in other systems that they're dependent on (eg a sprite might want a position, though it may accept any vector (shared or unshared) for that position)
  • Generally take those references in their constructor
  • Generally designed to have a nice oop-y method interface, rather than be "just" data - eg sprite:set_frame(fx, fy), animation:reset() etc


  • Do stuff with their set of components
View jprof-churn.lua
--baseline vs churn "try it yourself" love demonstration
--byo jprof
local prof = require("jprof")
--starting parameters
local churn = 1e3
local baseline = 1e5
local baseline_change_per_frame = 1e3
1bardesign / loop_benchmark.lua
Last active Jul 23, 2019
a microbenchmark comparing different loop types, and different work size per-iteration
View loop_benchmark.lua
local replicas = 3
local test_duration = 0.5
local single_test_size = 1e3
--per-iteration operation
function test_operation(a, b, work_size)
for _ = 1, work_size do
local s = tostring(a + b)