Skip to content

Instantly share code, notes, and snippets.

Michael Ebens mebens

View GitHub Profile
@mebens
mebens / gist:3949839
Created Oct 25, 2012
Reverse a table in Lua
View gist:3949839
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 / 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)
@mebens
mebens / gist:3911360
Created Oct 18, 2012
Hz frequencies of the notes from eight octaves in a Lua table.
View gist:3911360
-- converted from http://www.seventhstring.com/resources/notefrequencies.html
notes = {
[0] = { ["c"] = 16.35, ["c#"] = 17.32, ["d"] = 18.35, ["d#"] = 19.45, ["e"] = 20.60, ["f"] = 21.83, ["f#"] = 23.12, ["g"] = 24.50, ["g#"] = 25.96, ["a"] = 27.50, ["a#"] = 29.14, ["b"] = 30.87, },
[1] = { ["c"] = 32.70, ["c#"] = 34.65, ["d"] = 36.71, ["d#"] = 38.89, ["e"] = 41.20, ["f"] = 43.65, ["f#"] = 46.25, ["g"] = 49.00, ["g#"] = 51.91, ["a"] = 55.00, ["a#"] = 58.27, ["b"] = 61.74, },
[2] = { ["c"] = 65.41, ["c#"] = 69.30, ["d"] = 73.42, ["d#"] = 77.78, ["e"] = 82.41, ["f"] = 87.31, ["f#"] = 92.50, ["g"] = 98.00, ["g#"] = 103.8, ["a"] = 110.0, ["a#"] = 116.5, ["b"] = 123.5, },
[3] = { ["c"] = 130.8, ["c#"] = 138.6, ["d"] = 146.8, ["d#"] = 155.6, ["e"] = 164.8, ["f"] = 174.6, ["f#"] = 185.0, ["g"] = 196.0, ["g#"] = 207.7, ["a"] = 220.0, ["a#"] = 233.1, ["b"] = 246.9, },
[4] = { ["c"] = 261.6, ["c#"] = 277.2, ["d"] = 293.7, ["d#"] = 311.1, ["e"] = 329.6, ["f"] = 349.2, ["f#"] = 370.0, ["g"] = 392.0, ["g#"] = 41
@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 / 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 / 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)
View gist:1044222
Also installing dependencies: libsgml
==> Downloading http://www.hick.org/code/skape/libsgml/libsgml-1.1.4.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
==> Patching
@mebens
mebens / big-buttom.scss
Created Jun 5, 2011
The CSS and Sass code for my blog on making a 3D CSS button.
View big-buttom.scss
// These are some nice reusable mixins I keep around
@mixin transition($type, $time, $ease) {
-webkit-transition: $type $time $ease;
transition: $type $time $ease;
}
@mixin border-radius($length) {
border-radius: $length;
-webkit-border-radius: $length;
@mebens
mebens / transition.scss
Created May 25, 2011
A transition Sass mixin
View transition.scss
@mixin transition($type, $time, $ease) {
-webkit-transition: $type $time $ease;
transition: $type $time $ease;
}
View metatable-thing.lua
foo = { hello = 3, world = 4 }
bar = setmetatable({ exclamation = 5 }, { __index = foo })
x = table.attributes(bar) -- I have no idea what would be a fitting name for this function
-- x = { hello = 3, world = 4, exclamation = 5 }
You can’t perform that action at this time.