Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "gd"
- local base = gd.createFromJpeg("base.jpg")
- local sizex, sizey = base:sizeXY()
- local frame = gd.create(sizex, sizey)
- local out = gd.createTrueColor(sizex, sizey)
- function lum(c)
- local r = base:red(c)
- local g = base:green(c)
- local b = base:blue(c)
- return (r+g+b)/3
- end
- frame:gifAnimBegin("out.gif", false, 0)
- for frm = 1, 32 do
- for x = 1, sizex do
- local startsort = 1
- local sortc = base:getPixel(x, 1)
- local sortw = lum(sortc)
- local sortlist = {{c = sortc, w = sortw}}
- for y = 2, sizey do
- local color = base:getPixel(x, y)
- local w = lum(color)
- if math.abs(w-sortw) > 8*(frm-1) then
- --stop building a "similar colors" line: sort it, draw it then start a new one
- table.sort(sortlist, function(a, b) return a.w < b.w end)
- for ly = 1, #sortlist do
- out:setPixel(x, startsort+ly-1, sortlist[ly].c) --sortlist[#sortlist-ly+1].c)
- --the #sortlist-ly+1 index allows easily switching between the order in which sorted lines are redrawn
- end
- startsort = y
- sortw = w
- sortlist = {{c = color, w = w}}
- else
- table.insert(sortlist, {c = color, w = w})
- end
- end
- end
- frame = out:createPaletteFromTrueColor(true, 60)
- frame:gifAnimAdd("out.gif", true, 0, 0, 8, gd.DISPOSAL_NONE)
- print("frame:", frm)
- end
- gd.gifAnimEnd("out.gif")
Advertisement
Add Comment
Please, Sign In to add comment