Skip to content

Instantly share code, notes, and snippets.

Michael Ebens mebens

Block or report user

Report or block mebens

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mebens
mebens / camera.lua
Created May 8, 2011
Example code for part 3 of my Cameras in Love2D tutorial series.
View camera.lua
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 / main.lua
Created Sep 6, 2011
Complete code for my tutorial on mouse dragging in Love2D.
View main.lua
function love.load()
rect = {
x = 100,
y = 100,
width = 100,
height = 100,
dragging = { active = false, diffX = 0, diffY = 0 }
}
end
@mebens
mebens / bit-shifts.lua
Created Apr 23, 2011
Functions for quick left and right bitwise shifts in Lua.
View bit-shifts.lua
function lshift(x, by)
return x * 2 ^ by
end
function rshift(x, by)
return math.floor(x / 2 ^ by)
end
@mebens
mebens / guide.sh
Created Jan 13, 2019
Setting up an up-to-date LAMP stack server on Ubuntu 18.04
View guide.sh
# 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 / Vector.lua
Created Jun 30, 2011
Vector class for my tutorial on Lua metatables.
View Vector.lua
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 / example.lua
Created Nov 16, 2012
Doubly linked list in Lua
View example.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 / gist:3904043
Created Oct 17, 2012
Generate sine wave tones in Love2D
View gist:3904043
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 / gist:4218802
Created Dec 5, 2012
Simple glow/bloom GLSL shader for Love2D
View gist:4218802
// 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 / postfx.lua
Created Dec 6, 2012
A post-processing effects manager for Love2D
View postfx.lua
postfx = {}
postfx.all = {}
postfx.active = true
local PixelEffect = class("PixelEffect")
function PixelEffect:initialize(effect)
self.effect = effect
self.active = true
end
@mebens
mebens / gist:3929259
Created Oct 22, 2012
Generate a linear radial gradient in Love2D
View gist:3929259
local function scale(x, min1, max1, min2, max2)
return min2 + ((x - min1) / (max1 - min1)) * (max2 - min2)
end
local function distance(x1, y1, x2, y2)
return math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
end
function radialGradient(radius)
local data = love.image.newImageData(radius * 2, radius * 2)
You can’t perform that action at this time.