Skip to content

Instantly share code, notes, and snippets.

@ZakBlystone
ZakBlystone / circles_and_arcs.lua
Last active December 23, 2020 09:17
GLua code for drawing circles and arcs with thickness
-- Circles and Arcs (CC0 Public Domain, free to use in whatever you want)
-- Created by: Zachary Blystone ( [email protected] )
-- Vertex cache to prevent table allocations during draw operations
local vertCache = {}
for i=1, 256 do vertCache[i] = { x = 0, y = 0, u = 0, v = 0, } end
-- Localized functions
local math_rad = math.rad
local math_pi = math.pi
@ZakBlystone
ZakBlystone / draw_sphere.lua
Created June 1, 2020 02:06
GLua code for drawing a sphere using the mesh library
-- Sphere drawing using mesh library (CC0 Public Domain, free to use in whatever you want)
-- Created by: Zachary Blystone ( [email protected] )
-- Localized functions
local mesh_position = mesh.Position
local mesh_normal = mesh.Normal
local mesh_color = mesh.Color
local mesh_userdata = mesh.UserData
local mesh_texcoord = mesh.TexCoord
local mesh_advance = mesh.AdvanceVertex
@ZakBlystone
ZakBlystone / sstv.lua
Last active June 17, 2020 09:27
GLua experiment to take a screenshot and generate an SSTV signal from it
-- SSTV experiment (CC0 Public Domain, free to use in whatever you want)
-- Created by: Zachary Blystone ( [email protected] )
local rate = 44100
local image = {}
local function co()
local dt = 1 / rate
local p = 0
@ZakBlystone
ZakBlystone / qrcode.lua
Created June 19, 2020 08:52
GLua QR-Code generation library
-- QRCode Library (CC0 Public Domain, free to use in whatever you want)
-- Created by: Zachary Blystone ( [email protected] )
-- Based on https://github.com/nayuki/QR-Code-generator
--[[
USAGE:
-- To create a QR code object:
-- (text)
-- (ecl, can be LOW, MEDIUM, QUARTILE, or HIGH)
@ZakBlystone
ZakBlystone / color_conversion.lua
Created January 8, 2022 09:12
GLua code for fast conversion between RGB / HSV without using Color objects
-- Color conversion (CC0 Public Domain, free to use in whatever you want)
-- Created by: Zachary Blystone ( [email protected] )
local _min, _max, _abs, _floor = math.min, math.max, math.abs, math.floor
local _permut = {
function(a,b,c) return a,b,c end,
function(a,b,c) return b,a,c end,
function(a,b,c) return c,a,b end,
function(a,b,c) return c,b,a end,
function(a,b,c) return b,c,a end,
@ZakBlystone
ZakBlystone / supertrace.lua
Created May 9, 2022 01:51
GLua code for performing mesh-based tracelines
-- "Supertrace" mesh tracing library
-- (CC0 Public Domain, free to use in whatever you want)
-- Created by: Zachary Blystone ( [email protected] )
--[[
This library performs a trace against an entity's visual meshes.
While it is not as optimized as it could be, you won't see
much of a framedrop on meshes with less than 5,000 triangles.
-- FastToScreen (CC0 Public Domain, free to use in whatever you want)
-- Created by: Zachary Blystone ( [email protected] )
-- Localized functions
local __vunpack = FindMetaTable("Vector").Unpack
local __cos = math.cos
local __sin = math.sin
local __min = math.min
local __tan = math.tan
local __abs = math.abs