Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --@client
- local function perf(threshold)
- return math.max(quotaAverage(), quotaUsed()) < quotaMax()*threshold
- end
- -- Music
- local succ, ret = pcall(function()
- bass.loadFile("pixels/music.ogg", "mono", function(obj, errno, errtxt)
- if obj then
- music = obj
- else
- errmsg = errtxt
- end
- end)
- end)
- if not succ then
- errmsg = tostring(ret)
- end
- -- Define colors
- colors = {
- ["\xff\xff\xff"] = Color(255, 255, 255),
- ["\x00\x00\x00"] = Color(0, 0, 0),
- ["\xff\x5f\x00"] = Color(255, 95, 0),
- ["\xff\xbf\x00"] = Color(255, 191, 0),
- ["\xdf\xff\x00"] = Color(223, 255, 0),
- ["\x7f\xff\x00"] = Color(127, 255, 0),
- ["\x1f\xff\x00"] = Color(31, 255, 0),
- ["\x00\xff\x3f"] = Color(0, 255, 63),
- ["\x00\xff\x9f"] = Color(0, 255, 159),
- ["\x00\xff\xff"] = Color(0, 255, 255),
- ["\x00\x9f\xff"] = Color(0, 159, 255),
- ["\x00\x3f\xff"] = Color(0, 63, 255),
- ["\x1f\x00\xff"] = Color(31, 0, 255),
- ["\x7f\x00\xff"] = Color(127, 0, 255),
- ["\xdf\x00\xff"] = Color(223, 0, 255),
- ["\xff\x00\xbf"] = Color(255, 0, 191),
- ["\xff\x00\x5f"] = Color(255, 0, 95),
- ["\xff\x00\x00"] = Color(255, 0, 0),
- ["\x7f\x7f\x7f"] = Color(127, 127, 127)
- }
- -- Load image
- local img = string.explode("\n", file.read("pixels/test_bars_h_big.ppm"))
- for i=1, #img-1 do
- if img[i][1] == "#" then
- table.remove(img, i)
- end
- end
- if img[1] ~= "P6" then error("Bad image header") end
- w, h = unpack(string.explode(" ", img[2]))
- w, h = tonumber(w), tonumber(h)
- if not (w and h) then error("Could not read image dimensions") end
- if img[3] ~= "255" then error("Bad image byte size") end
- if #img ~= 4 then error("Too many newlines in image") end
- img_proc = {}
- --img[4] = string.rep("abcdefghi", w*h/3)
- for x=1, h do
- img_proc[x] = {}
- for y=1, w do
- local pos = (x*y)*3
- img_proc[x][y] = colors[string.sub(img[4], pos-2, pos)] or Color(31, 31, 31)
- end
- end
- --printTable(img_proc[1])
- -- Render
- hook.add("render", "init", function()
- local rt = render.createRenderTarget("rt")
- local size = 1024/math.max(w, h)
- render.selectRenderTarget("rt")
- for x=1, h do
- --if not perf(0.9) then break end
- for y=1, w do
- render.setColor(img_proc[x][y])
- render.drawRect(size*y, size*x, size, size)
- end
- end
- render.selectRenderTarget()
- hook.remove("render", "init")
- end)
- hook.add("render", "render", function()
- render.setRGBA(255, 255, 255, 255)
- render.drawRectFast(0, 0, 512, 512)
- render.setRenderTargetTexture("rt")
- render.drawTexturedRectFast(0, 0, 512, 512)
- render.setRenderTargetTexture()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement