Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ro = function(input, max)
- return math.floor(input % max)
- end
- local stringShift = function(str,amt)
- return str:sub(ro(amt-1,#str)+1)..str:sub(1,ro(amt-1,#str))
- end
- --[[
- Example on how to use:
- local grid = { ---That's how the grid is formatted.
- "+---",
- "| ",
- "| ",
- }
- local x,y = term.getSize()
- --If you want to fill the whole screen with that grid, then:
- drawGrid(1, 1, x, y, 0, 0)
- --and if you want a specific coloration, you can add bg color and txt color as two more arguments.
- --]]
- function drawGrid(_x1,_y1,_x2,_y2,grid,_xscroll,_yscroll,_bgcol,_txtcol)
- local scr_x, scr_y = term.getSize()
- local _txt, _bg = term.getTextColor(), term.getBackgroundColor()
- local _x, _y = term.getCursorPos()
- local xscroll, yscroll = _xscroll or 0, _yscroll or 0
- local x1,x2,y1,y2 = _x1,_x2,_y1,_y2
- if _x2 < _x1 then
- x1,x2=_x2,_x1
- end
- if _y2 < _y1 then
- y1,y2=_y2,_y1
- end
- local lenx, leny = (x2-x1)+1, y2-y1
- if _bgcol then
- term.setBackgroundColor(_bgcol)
- end
- if _txtcol then
- term.setTextColor(_txtcol)
- end
- for y = y1, y2 do
- term.setCursorPos(x1,y)
- term.write(stringShift(grid[ro(y+(yscroll+2),#grid)+1],xscroll+1):rep(math.ceil(lenx/#grid[ro(y+(yscroll+2),#grid)+1])):sub(1,lenx))
- end
- term.setCursorPos(_x,_y)
- term.setBackgroundColor(_bg)
- term.setTextColor(_txt)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement