Advertisement
Guest User

title

a guest
Dec 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. local mon = peripheral.wrap("monitor_3")
  2. local title={}
  3.  
  4. mon.setTextScale(1)
  5. mon.setTextColor(colors.white)
  6. mon.setBackgroundColor(colors.black)
  7.  
  8. function setTitle(name, xmin, xmax, ymin, ymax)
  9.     title[name] = {}
  10.     title[name]["xmin"] = xmin
  11.     title[name]["xmax"] = xmax
  12.     title[name]["ymin"] = ymin
  13.     title[name]["ymax"] = ymax
  14. end
  15.  
  16. function fill(text, color, bData)
  17.    mon.setBackgroundColor(color)
  18.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  19.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  20.    for j = bData["ymin"], bData["ymax"] do
  21.       mon.setCursorPos(bData["xmin"], j)
  22.       if j == yspot then
  23.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  24.             if k == xspot then
  25.                mon.write(text)
  26.             else
  27.                mon.write(" ")
  28.             end
  29.          end
  30.       else
  31.          for i = bData["xmin"], bData["xmax"] do
  32.             mon.write(" ")
  33.          end
  34.       end
  35.    end
  36.    mon.setBackgroundColor(colors.black)
  37. end
  38.  
  39. function screen()
  40.   for name,data in pairs(title) do
  41.     fill(name, colors.lime, data)
  42.   end
  43. end
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. function heading(text)
  51.    w, h = mon.getSize()
  52.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  53.    mon.write(text)
  54. end
  55.      
  56. function label(w, h, text)
  57.    mon.setCursorPos(w, h)
  58.    mon.write(text)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement