Advertisement
LDDestroier

PUE Minified

Dec 13th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.82 KB | None | 0 0
  1. local round = function(x) return x + 0.5 - (x + 0.5) % 1 end local deepCopy = function(tbl) return {table.unpack(tbl)} end local bcol, ccol = { [0]=" ",[colors.white]="0",[colors.orange]="1",[colors.magenta]="2",[colors.lightBlue]="3",[colors.yellow]="4",[colors.lime]="5",[colors.pink]="6",[colors.gray]="7",[colors.lightGray]="8",[colors.cyan]="9",[colors.purple]="a",[colors.blue]="b",[colors.brown]="c",[colors.green]="d",[colors.red]="e",[colors.black]="f"}, {} for k,v in pairs(bcol) do ccol[v] = k end paintutils.flipY = function(image) local output = {} for y = #image, 1, -1 do output[#output+1] = image[y] end return output end paintutils.flipX = function(image) local output,sizeX = {}, 0 for y = 1, #image do sizeX = math.max(sizeX,#image[y]) end for y = 1, #image do output[y] = {} for x = 1, sizeX do output[y][x] = deepCopy(image)[y][sizeX-(x-1)] or 0 end end return output end paintutils.grayOut = function(image) local output,grays = {},{[0] = 0,[colors.white]=colors.white,[colors.orange]=colors.lightGray,[colors.magenta]=colors.lightGray,[colors.lightBlue]=colors.lightGray,[colors.yellow]=colors.white,[colors.lime]=colors.lightGray,[colors.pink]=colors.lightGray,[colors.gray]=colors.gray,[colors.lightGray]=colors.lightGray,[colors.cyan]=colors.lightGray,[colors.purple]=colors.gray,[colors.blue]=colors.gray,[colors.brown]=colors.gray,[colors.green]=colors.lightGray,[colors.red]=colors.gray,[colors.black]=colors.black} for y = 1, #image do output[y] = {} for x = 1, #image[y] do output[y][x] = grays[image[y][x]] or image[y][x] end end return output end paintutils.lighten = function(image) local output,lighters = {},{[0] = 0,[colors.white] = colors.white,[colors.orange] = colors.yellow,[colors.magenta] = colors.pink,[colors.lightBlue] = colors.white,[colors.yellow] = colors.white,[colors.lime] = colors.white,[colors.pink] = colors.white,[colors.gray] = colors.lightGray,[colors.lightGray] = colors.white,[colors.cyan] = colors.lightBlue,[colors.purple] = colors.magenta,[colors.blue] = colors.lightBlue,[colors.brown] = colors.orange,[colors.green] = colors.lime,[colors.red] = colors.magenta,[colors.black] = colors.gray} for y = 1, #image do output[y] = {} for x = 1, #image[y] do output[y][x] = lighters[image[y][x]] or image[y][x] end end return output end paintutils.darken = function(image) local output, darkers = {},{[0]=0,[colors.white]=colors.lightGray,[colors.orange]=colors.brown,[colors.magenta]=colors.purple,[colors.lightBlue]=colors.cyan,[colors.yellow]=colors.orange,[colors.lime]=colors.green,[colors.pink]=colors.magenta,[colors.gray]=colors.black,[colors.lightGray]=colors.gray,[colors.cyan]=colors.blue,[colors.purple]=colors.gray,[colors.blue]=colors.gray,[colors.brown]=colors.black,[colors.green]=colors.gray,[colors.red]=colors.gray,[colors.black]=colors.black} for y = 1, #image do output[y] = {} for x = 1, #image[y] do output[y][x] = darkers[image[y][x]] or image[y][x] end end return output end paintutils.getSize = function(image) local xsize = 0 if type(image) ~= "table" then return 0,0 end for y = 1, #image do xsize = math.max(xsize,#image[y]) end return xsize, #image end paintutils.stretchImage = function(_image,sx,sy) local image,output = deepCopy(_image), {} if sx == 0 or sy == 0 then return {{}} end if sx < 0 then image = paintutils.flipX(image) end if sy < 0 then image = paintutils.flipY(image) end sx,sy = round(math.abs(sx)), round(math.abs(sy)) if sx == 0 or sy == 0 then return {{}} end local imX,imY = paintutils.getSize(image) local xcur,ycur for y = 1, sy do output[y] = {} for x = 1, sx do output[y][x] = image[math.max(1,round((y/sy)*imY))][math.max(1,round((x/sx)*imX))] or nil end end return output end paintutils.drawImageBlit = function(image,ix,iy) if (type(image) ~= "table") or (type(ix) ~= "number") or (type(iy) ~= "number") then error("Expected image, x, y", 2) else ix, iy = round(ix), round(iy) local buff for y = 1, #image do buff = "" for x = 1, #image[y] do buff = buff..bcol[image[y][x]] end term.setCursorPos(ix,iy+(y-1)) term.blit(buff,buff,buff) end end end paintutils.centerWithBlankSpace = function(_image,ix,iy,object) local image,scX,scY = deepCopy(_image) if object then scX,scY = object.getSize() else scX,scY = term.getSize() end local imgXsize,imgYsize = paintutils.getSize(image) if imgXsize == 0 or imgYsize == 0 then return {{}} end local incX,incY = math.floor((ix or (scX/2)) - (imgXsize/2)), math.floor((iy or (scY/2)) - (imgYsize/2)) local output = {} for y = 1, imgYsize + incY do output[y] = {} for x = 1, imgXsize + incX do if (x > incX) and (y > incY) then output[y][x] = image[y-incY][x-incX] or 0 else output[y][x] = 0 end end end return output end paintutils.drawImageBlitCenter = function(image,ix,iy,object) local scX,scY if object then scX,scY = object.getSize() else scX,scY = term.getSize() end local imgXsize,imgYsize = paintutils.getSize(image) return paintutils.drawImageBlit(image, (ix or (scX/2)) - (imgXsize/2), (iy or (scY/2)) - (imgYsize/2)) end  paintutils.drawImageCenter = function(image,ix,iy,object) local scX,scY if object then scX,scY = object.getSize() else scX,scY = term.getSize() end local imgXsize,imgYsize = paintutils.getSize(image) return paintutils.drawImage(image, (ix or (scX/2)) - (imgXsize/2), (iy or (scY/2)) - (imgYsize/2)) end paintutils.merge = function(...) local output,arg,imgXsize,imgYsize,image,xdiff,ydiff = {}, table.pack(...), 0, 0 for a = 1, #arg do local x,y = paintutils.getSize(arg[a][1]) if not (x == 0 or y == 0) then x, y = x+arg[a][2], y+arg[a][3] imgXsize = math.max(imgXsize,x) imgYsize = math.max(imgYsize,y) end end for a = #arg, 1, -1 do image,xdiff,ydiff = table.unpack(arg[a]) xdiff, ydiff = xdiff - 1, ydiff - 1 for y = 1, imgYsize do output[y] = output[y] or {} for x = 1, imgXsize do output[y][x] = output[y][x] or 0 if image[y-ydiff] then if image[y-ydiff][x-xdiff] and (image[y-ydiff][x-xdiff] ~= 0) then output[y][x] = image[y-ydiff][x-xdiff] end end end end end return output end paintutils.fullScreen = function(bgcol,object) local scr_x,scr_y = (object or term).getSize() local output,l = {},{} bgcol = bgcol or colors.black for x = 1, scr_x do l[x] = bgcol end for y = 1, scr_y do output[y] = l end return output end paintutils.unloadImage = function(image) local output = "" for y = 1, #image do for x = 1, #image[y] do output = output..bcol[image[y][x]] end if y < #image then output = output.."\n" end end return output end paintutils.autocrop = function(image) local output,top,leftings = {},1,{} local isTopped = false for a = 1, #image do if (not isTopped) and (#image[a] > 0) then top = a isTopped = true end if isTopped then output[#output+1] = deepCopy(image[a]) end end for y = 1, #output do leftings[y] = 0 for x = 1, #output[y] do if (output[y][x] == 0) or (output[y][x] == nil) then leftings[y] = leftings[y] + 1 else break end end end local left = math.min(table.unpack(leftings)) for y = 1, #output do for l = 1, left do table.remove(output[y],1) end end return output end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement