Advertisement
taoshi

Place text with brail border

Jun 12th, 2024
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | Gaming | 0 0
  1. local border={}
  2. local component = require'component'
  3. local unicode = require('unicode')
  4. local gpu = require('component').gpu
  5. local b = 0x2800 --brail
  6. --local bits = {1,8,2,16,4,32,64,128}
  7. local line={
  8.   left=unicode.char(184+b),
  9.   right=unicode.char(71+b),
  10.   top=unicode.char(192+b),
  11.   bottom=unicode.char(9+b),
  12.   lefttop=unicode.char(128+b),
  13.   leftbottom=unicode.char(8+b),
  14.   righttop=unicode.char(64+b),
  15.   rightbottom=unicode.char(1+b)
  16. }
  17.  
  18. function border.box(x,x2,y,y2)
  19.   local topline = line.lefttop
  20.   local bottomline = line.leftbottom
  21.   for _ = x, x2 , 1 do
  22.     topline = topline .. line.top
  23.     bottomline = bottomline .. line.bottom
  24.   end
  25.   topline = topline .. line.righttop
  26.   bottomline = bottomline .. line.rightbottom
  27.  
  28.   gpu.set(x-1,y-1,topline)
  29.   for f=y,y2,1 do
  30.     gpu.set(x-1,f,line.left)
  31.     gpu.set(x2+1,f,line.right)
  32.   end
  33.   gpu.set(x-1,y2+1,bottomline)
  34.   return true
  35.  
  36. end
  37. --text by custom coords with color attributes
  38. function border.put(text,x,y,font,field,box)
  39.   if text then
  40.     text=tostring(text)
  41.   else text = 'put your text here'
  42.   end
  43.  
  44.   x=x or 2
  45.   y=y or 2
  46.   box = box or 0xa000a0
  47.   field = field or 0x00e000
  48.   font = font or 0xf00000
  49.  
  50.   local foreground = gpu.getForeground()
  51.   local background = gpu.getBackground()
  52.  
  53.   gpu.setForeground(box)
  54.   border.box(x,x+#text-1,y,y)
  55.   gpu.setForeground(font) gpu.setBackground(field)
  56.   gpu.set(x,y,text)
  57.   gpu.setBackground(background) gpu.setForeground(foreground)
  58.   return true
  59. end
  60.  
  61. local energy={' ','K ','M ','G ','T ','P '}
  62. --конвертирует число  в тир энергии
  63. function border.energyTier(number,energy_name)
  64.   energy_name = energy_name or 'RF/t'
  65.   local tier=1
  66.   while number>1000 do
  67.     tier=tier+1 number=number/1000
  68.     if tier == #energy then break end
  69.   end
  70.   number = string.sub(number,1,5)
  71.   return(number..energy[tier]..energy_name),tier
  72. end
  73.  
  74. --[[
  75. local num = tostring(number)
  76. local tier = tostring(#number//1)//3
  77.  
  78.  
  79.  
  80. function printNumArrayAsTable(numArray)
  81.  
  82.   return true
  83. end
  84. ]]
  85.  
  86. function border.getDevice(name)
  87. local name=name or 'computer'  
  88. local device={}
  89.   local c=component.list()
  90.   for k,v in pairs(c) do if string.find(v,name) then
  91.     device[#device+1]=component.proxy(k) end
  92.   end
  93.   return device
  94. end
  95.  
  96. return border
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement