Advertisement
astonish01

Monitors

Feb 13th, 2025
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.71 KB | None | 0 0
  1. monitor = peripheral.wrap('top')
  2. modem = peripheral.wrap('bottom')
  3. modem.open(32)
  4.  
  5. --draws a box of x2-x1/y2-y1 pixels at given coordinates, corner at x1,y1
  6. function drawBox(x1,x2,y1,y2,terminal,c)
  7.     prevcolor = terminal.getBackgroundColor()
  8.     for i = x1, x2 do
  9.         for j= y1, y2 do
  10.             terminal.setBackgroundColor(c)
  11.             terminal.setCursorPos(i,j)
  12.             terminal.write(" ")
  13.         end
  14.     end
  15.     terminal.setBackgroundColor(prevcolor)
  16. end
  17.  
  18. --draws a plus sign
  19. function drawPlus(x1,x2,y1,y2,terminal,c)
  20.     prevcolor = terminal.getBackgroundColor()
  21.     --odd
  22.     if (math.mod(x2-x1,2) == 0) or (math.mod(y2-y1,2) == 0) then
  23.         middleX = (x2+x1)/2
  24.         middleY = (y2+y1)/2
  25.         --horizontal
  26.         for i=x1,x2 do
  27.             terminal.setBackgroundColor(c)
  28.             terminal.setCursorPos(i,middleY)
  29.             terminal.write(" ")
  30.         end
  31.         --vertical
  32.         for j=y1,y2 do
  33.             terminal.setBackgroundColor(c)
  34.             terminal.setCursorPos(middleX,j)
  35.             terminal.write(" ")
  36.         end
  37.     --even
  38.     else if (math.mod(x2-x1,2) ~= 0) or (math.mod(y2-y1,2) ~= 0) then
  39.         middleleft,middleright = x2-1,x2/2
  40.         middlebottom,middlettop = y2-1,y2/2
  41.         --vertical
  42.         for i=middleleft,middleright do
  43.             for j=y1,y2 do
  44.                 terminal.setBackgroundColor(c)
  45.                 terminal.setCursorPos(i,j)
  46.                 terminal.write(" ")
  47.             end
  48.         end
  49.         --horizontal
  50.         for k=x1,x2 do
  51.             for l=middleleft,middleright do
  52.                 terminal.setBackgroundColor(c)
  53.                 terminal.setCursorPos(k,l)
  54.                 terminal.write(" ")
  55.             end
  56.         end
  57.         else
  58.             return print("not a square")
  59.         end
  60.     end
  61.     terminal.setBackgroundColor(prevcolor)
  62. end
  63.  
  64. --draws a minus sign
  65. function drawMinus(x1,x2,y1,y2,terminal,c)
  66.     prevcolor = terminal.getBackgroundColor()
  67.     --odd
  68.     if (math.mod(x2-x1,2) == 0) or (math.mod(y2-y1,2) == 0) then
  69.         middleY = (y1+y2)/2
  70.         middleX = (x1+x2)/2
  71.         for i=x1,x2 do
  72.             terminal.setBackgroundColor(c)
  73.             terminal.setCursorPos(i,middleY)
  74.             terminal.write(" ")
  75.         end
  76.     --even
  77.     elseif (math.mod(x2-x1,2) ~= 0) or (math.mod(y2-y1,2) ~= 0) then
  78.         bottomY,topY = y2-1,y2/2
  79.         for i=x1,x2 do
  80.             for j=topY,bottomY do
  81.             terminal.setBackgroundColor(c)
  82.             terminal.setCursorPos(i,j)
  83.             terminal.write(" ")
  84.             end
  85.         end
  86.     else
  87.         print("uh oh, something went wrong UwU")
  88.     end
  89.     terminal.setBackgroundColor(prevcolor)
  90. end
  91.  
  92. --sets up monitors
  93. function monitorSetup(terminal,linhas)
  94.     terminal.setBackgroundColor(colors.black)
  95.     terminal.setTextColor(colors.white)
  96.     terminal.clear()
  97.     terminal.setTextScale(1)
  98.     for i=1, 4 do
  99.         terminal.setCursorPos(1,i)
  100.         terminal.write(linhas[i])
  101.     end
  102.     drawBox(2,7,8,11,terminal,colors.red)
  103.     terminal.setCursorPos(2,6)
  104.     terminal.write("TOGGLE")
  105.     terminal.setCursorPos(2,7)
  106.     terminal.write("CIRCLE")
  107.     terminal.setCursorPos(11,6)
  108.     terminal.write("CRAFT")
  109.     terminal.setCursorPos(11,7)
  110.     terminal.write("NUMBER:0")
  111.     --botao de +
  112.     drawBox(11,13,8,10,terminal,colors.red)
  113.     drawPlus(11,13,8,10,terminal,colors.white)
  114.     --botao de -
  115.     drawBox(16,18,8,10,terminal,colors.red)
  116.     drawMinus(16,18,8,10,terminal,colors.white)
  117. end
  118.  
  119. --toggle circle area check
  120. function checkToggle(x,y)
  121.     clickInButton = false
  122.     for i=2,7 do
  123.         for j=8,11 do
  124.             if i==x and j==y then
  125.                 clickInButton = true
  126.             end
  127.         end
  128.     end
  129.     return clickInButton
  130. end
  131.  
  132. monitorlines = {"Uphyxes Inv Tower","Eziveus' Spec Compulsion","Strigeor's High Binding","Sevira's Perma Confinement"}
  133. --monitorlines2 = {"Abra's Norm/Open/Fort Conj","Aviar's Circle","Ophyx' Calling","Fatma's Incent Attract"}
  134. --monitorlines3 = {"Abra's Com/Open Com Conj","Ihagan's Enthrallment","Hedyrin's Lure","Xeovrenth Adjure"}
  135. --monitorlines4 = {"Ronazas Contact","","",""}
  136. while true do
  137.     monitorSetup(monitor,monitorlines)
  138.     repeat
  139.     e, s, cX, cY = os.pullEvent("monitor_touch")
  140.     until e ~= nil
  141.     if checkToggle(cX,cY) then
  142.         modem.transmit(1,32,"potato")
  143.     end
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement