Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --https://i.imgur.com/qnrhCW2.png
- local MAX = 100 --максимальное значение
- local level = 0 --переменное значение
- local step = 1 --шаг заполнения
- local com = require("component")
- local event = require("event")
- local gpu = com.gpu
- local WIDTH,HEIGHT = gpu.getResolution()
- local function drawBar(x,y,width,value,max,color)
- local line = string.rep(" ",width-2)
- gpu.setForeground(0xffffff)
- gpu.setBackground(0x000000)
- gpu.fill(x,y,width+2,2," ")
- gpu.set(x,y,"┍"..line.."┑")
- gpu.set(x,y+1,"│"..line.."│")
- gpu.set(x,y+2,"┕"..line.."┙")
- local width = width-2
- local len = math.ceil(width*(value/max))
- gpu.setForeground(color)
- gpu.set(x+1,y,string.rep("▗",len))
- gpu.set(x+1,y+1,string.rep("▐",len))
- gpu.setForeground(color*0.6)
- gpu.set(x+1,y+2,string.rep("▝",len))
- gpu.setForeground(0x222222)
- gpu.set(x+1+len,y,string.rep("▗",width-len))
- gpu.set(x+1+len,y+1,string.rep("░",width-len))
- gpu.set(x+1+len,y+2,string.rep("▝",width-len))
- end
- local function use()
- local e, a, x, y, s = event.pull() --(0.2)
- if e == "touch" or e == "drag" then
- if y >= 6 and y <= 8 then
- if x > 1 and x < WIDTH then
- level = math.ceil((x-3)/(WIDTH-4)*MAX)
- end
- end
- elseif e == "key_down" or e == "scroll" then
- if y == 205 or s and s == 1 then
- level = level + step
- elseif y == 203 or s and s == -1 then
- level = level - step
- end
- end
- if level > MAX then
- level = MAX
- elseif level < 0 then
- level = 0
- end
- end
- gpu.fill(1,1,WIDTH,HEIGHT," ")
- while true do
- gpu.setForeground(0xffb600)
- gpu.set(3,5,"level = "..level.." ")
- gpu.set(WIDTH-8,5,tostring(MAX).." max")
- drawBar(2,6,78,level,MAX,0x00BB00)
- use()
- end
Add Comment
Please, Sign In to add comment