Created
November 5, 2013 13:52
-
-
Save TannerRogalsky/7319282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "gd" | |
function project(px, py, pz, win_width, win_height, fov, cam) | |
local factor = fov / (cam+pz) | |
local x = px*factor + win_width/2 | |
local y = -py*factor + win_height/2 | |
return x, y | |
end | |
local base = gd.createFromJpeg("base.jpg") | |
local basepal = base:createPaletteFromTrueColor(true, 150) | |
local black = basepal:colorAllocate(0, 0, 0) | |
local sizex, sizey = base:sizeXY() | |
local colors = {} | |
for x = 1, sizex do | |
colors[x] = {} | |
for y = 1, sizey do | |
local color = base:getPixel(x, y) | |
local colorpal = basepal:getPixel(x, y) | |
colors[x][y] = { | |
r = base:red(color), | |
g = base:green(color), | |
b = base:blue(color), | |
p = colorpal} | |
local c = colors[x][y] | |
c.w = (c.r+c.g+c.b)/3 | |
end | |
end | |
local xo = {} | |
for x = 1, sizex/2 do table.insert(xo, x) end | |
for x = sizex, sizex/2, -1 do table.insert(xo, x) end | |
basepal:gifAnimBegin("out.gif", true, 0) | |
for frm = 0, 29 do | |
local prev = basepal | |
basepal:filledRectangle(0, 0, sizex, sizey, black) | |
for _, x in pairs(xo) do | |
for y = 1, sizey do | |
local px, py = project(x-sizex/2, -y+sizey/2, | |
-frm*math.pow(math.max(0, colors[x][y].w-20)/200, 3), sizex, sizey, 30, 30) | |
basepal:setPixel(px, py, colors[x][y].p) | |
end | |
end | |
basepal:gifAnimAdd("out.gif", false, 0, 0, 5, gd.DISPOSAL_NONE, prev) | |
--gd.DISPOSAL_RESTORE_BACKGROUND) | |
print("frame", frm) | |
end | |
gd.gifAnimEnd("out.gif") | |
os.execute("out.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment