Skip to content

Instantly share code, notes, and snippets.

@mebens
mebens / bit-shifts.lua
Created April 23, 2011 09:39
Functions for quick left and right bitwise shifts in Lua.
function lshift(x, by)
return x * 2 ^ by
end
function rshift(x, by)
return math.floor(x / 2 ^ by)
end
@mebens
mebens / gist:4218802
Created December 5, 2012 19:36
Simple glow/bloom GLSL shader for Love2D
// adapted from http://www.youtube.com/watch?v=qNM0k522R7o
extern vec2 size;
extern int samples = 5; // pixels per axis; higher = bigger glow, worse performance
extern float quality = 2.5; // lower = smaller glow, better quality
vec4 effect(vec4 colour, Image tex, vec2 tc, vec2 sc)
{
vec4 source = Texel(tex, tc);
vec4 sum = vec4(0);
@mebens
mebens / gist:3949839
Created October 25, 2012 00:44
Reverse a table in Lua
function table.reverse(t)
local len = #t + 1
for i = 1, math.floor(#t / 2) do
t[i], t[len - i] = t[len - i], t[i]
end
return t
end
@mebens
mebens / Vector.lua
Created June 30, 2011 01:56
Vector class for my tutorial on Lua metatables.
Vector = {}
Vector.__index = Vector
function Vector.__add(a, b)
if type(a) == "number" then
return Vector.new(b.x + a, b.y + a)
elseif type(b) == "number" then
return Vector.new(a.x + b, a.y + b)
else
return Vector.new(a.x + b.x, a.y + b.y)
@mebens
mebens / main.lua
Created September 6, 2011 00:13
Complete code for my tutorial on mouse dragging in Love2D.
function love.load()
rect = {
x = 100,
y = 100,
width = 100,
height = 100,
dragging = { active = false, diffX = 0, diffY = 0 }
}
end
@mebens
mebens / camera.lua
Created May 8, 2011 20:52
Example code for part 3 of my Cameras in Love2D tutorial series.
camera = {}
camera._x = 0
camera._y = 0
camera.scaleX = 1
camera.scaleY = 1
camera.rotation = 0
function camera:set()
love.graphics.push()
love.graphics.rotate(-self.rotation)
@mebens
mebens / example.lua
Created November 16, 2012 04:24
Doubly linked list in Lua
require("list")
local a = { 3 }
local b = { 4 }
local l = list({ 2 }, a, b, { 5 })
l:pop()
l:shift()
l:push({ 6 })
l:unshift({ 7 })
@mebens
mebens / guide.sh
Created January 13, 2019 07:46
Setting up an up-to-date LAMP stack server on Ubuntu 18.04
# Script correlating to tutorial at http://ebens.me/post/install-lamp-stack-ubuntu
# Even though you probably could, don't run it all at once
# new user
adduser new_user
usermod -a -G sudo new_user
su - new_user
# new repos
@mebens
mebens / gist:3904043
Created October 17, 2012 06:36
Generate sine wave tones in Love2D
local samples = 100000
local data = love.sound.newSoundData(samples)
local noteChange = 10000
local note = 200
local change = 50
local minimum = 100
for i = 0, samples * 2 - 1 do
if i % noteChange == 0 then
local factor = -2 + math.random(0, 4)
@mebens
mebens / postfx.lua
Created December 6, 2012 02:30
A post-processing effects manager for Love2D
postfx = {}
postfx.all = {}
postfx.active = true
local PixelEffect = class("PixelEffect")
function PixelEffect:initialize(effect)
self.effect = effect
self.active = true
end