Advertisement
Guest User

col

a guest
Feb 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. -- * Monitorseite: left, right, back, bottom,
  2. --   down, up
  3. local monitor = peripheral.wrap("back")
  4.  
  5. -- * SchriftgråB6sse: 1 oder gråB6sser
  6. local size = 2.5
  7.  
  8. function createBar(yPos, start, stop, time, color)
  9.   interval = math.floor((start - stop) / (time * 10))
  10.  
  11.   if (interval > 0) then
  12.     for i = start,stop,(interval * (-1)) do
  13.       if (i < stop) then
  14.         return
  15.       end
  16.      
  17.       monitor.setCursorPos(1,yPos)
  18.       monitor.clearLine()
  19.       monitor.setBackgroundColor(color)
  20.      
  21.       for j = stop,i,1 do
  22.         monitor.write(" ")
  23.       end
  24.      
  25.       monitor.setBackgroundColor(colors.black)
  26.      
  27.       sleep(time)
  28.     end
  29.   end
  30. end
  31.  
  32. function setBackground(color)
  33.   monitor.setBackgroundColor(color)
  34. end
  35.  
  36. function getColor(color)
  37.   if (color == "f") then
  38.     return 1
  39.   elseif (color == "6") then
  40.     return 2
  41.   elseif (color == "4") then
  42.     return 4
  43.   elseif (color == "b") then
  44.     return 8
  45.   elseif (color == "e") then
  46.     return 16
  47.   elseif (color == "a") then
  48.     return 32
  49.   elseif (color == "d") then
  50.     return 64
  51.   elseif (color == "8") then
  52.     return 128
  53.   elseif (color == "7") then
  54.     return 256
  55.   elseif (color == "3") then
  56.     return 512
  57.   elseif (color == "5") then
  58.     return 1024
  59.   elseif (color == "9") then
  60.     return 2048
  61.   elseif (color == "1") then
  62.     return 4096
  63.   elseif (color == "2") then
  64.     return 8192
  65.   elseif (color == "c") then
  66.     return 16384
  67.   elseif (color == "0") then
  68.     return 32768
  69.   end
  70. end
  71.  
  72. function clear()
  73.   monitor.clear()
  74. end
  75.  
  76. function createButton(yPos, height, xPos, length, name, color)
  77.   for y = 1, height do
  78.     monitor.setCursorPos(xPos, (y - 1) + yPos)
  79.     monitor.setBackgroundColor(color)
  80.    
  81.     if (y == math.floor((height / 2) + 0.5)) then
  82.       number = math.floor((length - name:len()) + 0.5)
  83.      
  84.       for x = 0, number do
  85.         if (x == math.floor((number / 2) + 0.5)) then
  86.           monitor.setTextColor(colors.black)
  87.           monitor.write(name)
  88.         else
  89.           monitor.write(" ")
  90.         end
  91.       end
  92.     else
  93.       for x = 1, length do
  94.           monitor.write(" ")
  95.       end
  96.     end
  97.    
  98.     monitor.setBackgroundColor(colors.black)
  99.   end
  100. end
  101.  
  102. function msg(line, text)
  103.   monitor.setCursorPos(1, line)
  104.   monitor.setTextColour(1)
  105.   monitor.setTextScale(size)
  106.  
  107.   local start = text:find("&")
  108.   local stop = 0
  109.   local color = ""
  110.        
  111.   if (start == nil) then
  112.     monitor.write(text)
  113.   else
  114.     if (start > 1) then
  115.       monitor.write(text:sub(0, start - 1))
  116.     end
  117.  
  118.     while (start ~= nil) do
  119.       stop = text:find("&", start + 2)
  120.       color = text:sub(start + 1, start + 1)
  121.       monitor.setTextColor(getColor(color))
  122.      
  123.       if (stop == nil) then
  124.         monitor.write(text:sub(start + 2))
  125.         break
  126.       else
  127.         monitor.write(text:sub(start + 2, stop - 1))
  128.         start = stop
  129.       end  
  130.     end
  131.   end
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement