serafim7

set bar от банка Totoro [OpenComputers]

Nov 19th, 2020 (edited)
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. --https://i.imgur.com/qnrhCW2.png
  2.  
  3. local MAX = 100 --максимальное значение
  4. local level = 0 --переменное значение
  5. local step = 1  --шаг заполнения
  6.  
  7. local com = require("component")
  8. local event = require("event")
  9. local gpu = com.gpu
  10. local WIDTH,HEIGHT = gpu.getResolution()
  11.  
  12. local function drawBar(x,y,width,value,max,color)
  13.   local line = string.rep(" ",width-2)
  14.   gpu.setForeground(0xffffff)
  15.   gpu.setBackground(0x000000)
  16.   gpu.fill(x,y,width+2,2," ")
  17.   gpu.set(x,y,"┍"..line.."┑")
  18.   gpu.set(x,y+1,"│"..line.."│")
  19.   gpu.set(x,y+2,"┕"..line.."┙")
  20.   local width = width-2
  21.   local len = math.ceil(width*(value/max))
  22.   gpu.setForeground(color)
  23.   gpu.set(x+1,y,string.rep("▗",len))
  24.   gpu.set(x+1,y+1,string.rep("▐",len))
  25.   gpu.setForeground(color*0.6)
  26.   gpu.set(x+1,y+2,string.rep("▝",len))
  27.   gpu.setForeground(0x222222)
  28.   gpu.set(x+1+len,y,string.rep("▗",width-len))
  29.   gpu.set(x+1+len,y+1,string.rep("░",width-len))
  30.   gpu.set(x+1+len,y+2,string.rep("▝",width-len))
  31. end
  32.  
  33. local function use()
  34.   local e, a, x, y, s = event.pull() --(0.2)
  35.   if e == "touch" or e == "drag" then
  36.     if y >= 6 and y <= 8 then
  37.       if x > 1 and x < WIDTH then
  38.         level = math.ceil((x-3)/(WIDTH-4)*MAX)
  39.       end
  40.     end
  41.   elseif e == "key_down" or e == "scroll" then
  42.     if y == 205 or s and s == 1 then
  43.       level = level + step
  44.     elseif y == 203 or s and s == -1 then
  45.       level = level - step
  46.     end
  47.   end
  48.   if level > MAX then
  49.     level = MAX
  50.   elseif level < 0 then
  51.     level = 0
  52.   end
  53. end
  54.  
  55. gpu.fill(1,1,WIDTH,HEIGHT," ")
  56.  
  57. while true do
  58.   gpu.setForeground(0xffb600)
  59.   gpu.set(3,5,"level = "..level.."  ")
  60.   gpu.set(WIDTH-8,5,tostring(MAX).." max")
  61.   drawBar(2,6,78,level,MAX,0x00BB00)
  62.   use()
  63. end
Add Comment
Please, Sign In to add comment