Skip to content

Instantly share code, notes, and snippets.

View 1bardesign's full-sized avatar

Max Cahill 1bardesign

View GitHub Profile
--baseline vs churn "try it yourself" love demonstration
--byo jprof
PROF_CAPTURE = true
local prof = require("jprof")
--starting parameters
local churn = 1e3
local baseline = 1e5
local baseline_change_per_frame = 1e3
@1bardesign
1bardesign / ecs_writeup.md
Last active June 2, 2020 13:42
Hopefully straightforward writeup on the design of my lua-side "ecs", which I should find a better name for.

Components:

  • 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

Systems:

  • Do stuff with their set of components
@1bardesign
1bardesign / main.lua
Last active May 17, 2020 23:57
simplified hydraulic erosion on the gpu in love
--[[
"Hydrosion"
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!
License:
@1bardesign
1bardesign / matrix_utility.lua
Created March 30, 2020 23:01
Perspective projection and camera lookat functions for love2d
--[[
matrix utility functions for love2d
expects vec3 from https://github.com/1bardesign/batteries
]]
return {
calculate_perspective = function(screen, fov, near, far, into)
--everything we need
local aspect = screen[1] / screen[2];
@1bardesign
1bardesign / metatable_example.lua
Created May 12, 2020 00:38
a heavily commented example of using metatables to implement class-like behaviour in 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
example_class.mt = {
--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
1bardesign / shader_try_send.lua
Created September 3, 2020 23:39
try to send a uniform to a shader without getting blocking errors when it's been optimised away
--[[
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
]]
do
local _warned = setmetatable({}, {__mode = "k"})
local function _warn(s, u)
local already_warned = _warned[s]
if not already_warned then
@1bardesign
1bardesign / texture_utils.lua
Last active October 1, 2020 02:14
texture utilities including various downsamples, dilation, and blurring
--texture utilities
--todo: clean up and include in https://github.com/1bardesign/batteries
--[[
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
1bardesign / conf.lua
Last active February 23, 2021 14:08
A little self-contained pomodoro timer for love2d
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!"
end
@1bardesign
1bardesign / oklab_snippet.glsl
Last active April 30, 2021 05:28
oklab to rgb and back for love2d glsl - see https://bottosson.github.io/posts/oklab/ - todo: polar coordinate mode
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
1bardesign / pixelart-pointers.md
Created March 23, 2022 23:53
tips and references for folks getting started with pixel art, and a little bit of philosphy too

This is a work in progress 🛠️

Pixel art

Pixel art is like art, but with pixels.

Generally the distinction is made at the point where the placement and colour relationships of individual pixels have a significant impact on the final piece, and where the artist is (or should be) concerned about optimising those relationships. This generally means both lower overall resolutions and lower colour counts, but there are many important works of pixel art that transcend those restrictions.

Pixel art and game art are often intertwined. Pixel art has long been used for game art because earlier systems had lower resolutions and lower colour counts, making a pixel art approach more important. It is important to understand, however, that the modern pixel art "movement" occurred significantly after those limited systems were mainstream, the modern understanding of pixel art has been developed in a reasonably post-hoc manner and the amount of academic interest in the movement is relatively tiny, with most of the folks