Advertisement
sshikamaru

Tuto - Bargraph vertical

Mar 25th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.88 KB | None | 0 0
  1. local computer = require("computer")
  2. local component = require("component")
  3. local term = require("term")
  4. local math = require("math")
  5. local event = require("event")
  6. local string = require("string")
  7.  
  8. local screen = component.getPrimary("screen")
  9. local gpu = component.gpu
  10. gpu.setResolution(63,25)
  11.  
  12. local v1 = 0
  13. local sens = true
  14.  
  15. local function setColor(bg,fg)
  16.   gpu.setBackground(bg)
  17.   gpu.setForeground(fg)
  18. end
  19.  
  20. local function barre_verticale(x,y,hauteur,largeur,valeur,valmax)
  21.   local k = 0
  22.   local cur = math.floor((valeur / valmax) * hauteur)
  23.   local dir = string.rep(" ",largeur)
  24.   for k = 1, hauteur do
  25.     local vy = y + hauteur - k
  26.     if k <= cur then
  27.       setColor(0x00FF00,0x0000FF)
  28.     elseif k > cur then
  29.       setColor(0x000000,0xFFFFFF)  
  30.     end
  31.       gpu.set(x,vy,dir)
  32.     if k == 1 then
  33.       gpu.set(x,vy,dir)
  34.       gpu.set(x,vy,string.format("Max %4s mB",valmax))
  35.     elseif k == 3 then
  36.       gpu.set(x,vy,dir)
  37.       gpu.set(x,vy,string.format("Cur %4s mB",valeur))
  38.     elseif k == 4 then
  39.       gpu.set(x,vy,dir)
  40.       gpu.set(x,vy,string.format("  %06.02f%%  ",(valeur/valmax)*100))
  41.     elseif k == 6 then
  42.       gpu.set(x,vy," Carburant ")
  43.     elseif k == 7 then
  44.       gpu.set(x,vy,"  Réserve  ")
  45.     end
  46.     setColor(0x000000,0xFFFFFF)
  47.   end
  48. end
  49.  
  50.  gpu.set(1,1,"╔═════════════════════════════════════════════════════════════╗")
  51.  gpu.set(1,2,"║                                                             ║")
  52.  gpu.set(1,3,"╠═════════════════════════════════════════════════════════════╣")
  53.  gpu.set(1,4,"║                                                             ║")
  54.  gpu.set(1,5,"║                                                             ║")
  55.  gpu.set(1,6,"║                                                             ║")
  56.  gpu.set(1,7,"║                                                             ║")
  57.  gpu.set(1,8,"║                                                             ║")
  58.  gpu.set(1,9,"║                                                             ║")
  59. gpu.set(1,10,"║                                                             ║")
  60. gpu.set(1,11,"║                                                             ║")
  61. gpu.set(1,12,"║                                                             ║")
  62. gpu.set(1,13,"║                                                             ║")
  63. gpu.set(1,14,"║                                                             ║")
  64. gpu.set(1,15,"║                                                             ║")
  65. gpu.set(1,16,"║                                                             ║")
  66. gpu.set(1,17,"║                                                             ║")
  67. gpu.set(1,18,"║                                                             ║")
  68. gpu.set(1,19,"║                                                             ║")
  69. gpu.set(1,20,"║                                                             ║")
  70. gpu.set(1,21,"║                                                             ║")
  71. gpu.set(1,22,"║                                                             ║")
  72. gpu.set(1,23,"║                                                             ║")
  73. gpu.set(1,24,"║                                                             ║")
  74. gpu.set(1,25,"╚═════════════════════════════════════════════════════════════╝")
  75.  
  76. local function onTouch(event,adress,x,y,clic,pseudo)
  77.   local tclic
  78.   if clic == 0  then
  79.     tclic = "Clic gauche"
  80.   elseif clic == 1 then
  81.     tclic = "Clic droit"
  82.   else
  83.     tclic = "Clic inconnu"
  84.   end
  85.   gpu.set(2,2," "..tclic.." de la part de "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y))
  86.   if clic == 0 then
  87.     if x==1 and y==1 then
  88.       computer.pushSignal("quit")
  89.       term.setCursor(1,1)
  90.       return false
  91.     elseif 1 == 0 then
  92.     end
  93.   end
  94. end
  95.  
  96. local function onTimer(_,timer)
  97.   if sens == true then
  98.     v1 = v1 + 4
  99.   elseif sens == false then
  100.     v1 = v1 - 4
  101.   end
  102.   if v1 == 400 then
  103.     sens = false
  104.   elseif v1 == 0 then
  105.     sens = true  
  106.   end  
  107.   gpu.set(50,3,string.format("%.02f       ",v1))
  108.   barre_verticale(30,4,25,7,v1,400)
  109.   barre_verticale(10,4,25,7,v1,400)
  110.   return true
  111. end
  112.  
  113. event.listen("touch",onTouch)
  114. local timer = event.timer(0.2,onTimer,math.huge)
  115. event.pull("quit")
  116. event.cancel(timer)
  117. event.ignore("touch",onTouch)
  118. gpu.setResolution(160,50)
  119. gpu.fill(1,1,160,50," ")
  120. term.clear()
  121.  
  122. --Créé par sshikamaru. Vous avez le droit de l'utiliser mais pas de le distribuer.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement