Advertisement
Guest User

print.lua

a guest
Oct 13th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.84 KB | None | 0 0
  1.  
  2. local colorscp = colorscp
  3. local colorsbp = colorsbp
  4. local paperp = paperp
  5.  
  6. local component = require("component")
  7.  
  8. local term = require("term")
  9.  
  10. local computer = require("computer")
  11.  
  12. local keyboard = require("keyboard")
  13.  
  14. local gpu = component.gpu
  15.  
  16. local colortable = {
  17.       {name = "red",   hex = 0xAA0000, hexs = "0xAA0000"},
  18.       {name = "green", hex = 0x00AA00, hexs = "0x00AA00"},
  19.       {name = "blue",  hex = 0x0000AA, hexs = "0x0000AA"},
  20.       {name = "black", hex = 0x000000, hexs = "0x000000"},
  21.       {name = "gray",  hex = 0xAAAAAA, hexs = "0xAAAAAA"},
  22.       {name = "white", hex = 0xFFFFFF, hexs = "0xFFFFFF"},
  23.       {name = "aqua",  hex = 0x00AAAA, hexs = "0x00AAAA"},
  24.       {name = "gold",  hex = 0xFFAA00, hexs = "0xFFAA00"}
  25. }
  26. local curcolor = curlolor
  27. if component.isAvailable("openprinter") then
  28.  
  29.   local printer = component.openprinter
  30.   local color = 0x0000ff
  31.   while true do
  32.     term.clear()
  33.     --╔═╗╚╝║
  34.     print(
  35.     [[
  36. ╔═══════════════════════════╗
  37. ║add text : для добавления  ║
  38. ║текста в очередь принтера.
  39. print : для начала печати  ║
  40. ║color : для выбора цвета   ║
  41. exit : для корректного     ║
  42. ║выхода из программы.       ║
  43. ╚═══════════════════════════╝
  44.      ]])
  45.      if printer.getColorInkLevel() == false then
  46.            colorscp = 0
  47.      else
  48.            colorscp = math.floor( printer.getColorInkLevel() / 4000 * 100 )
  49.      end
  50.  
  51.      if printer.getBlackInkLevel() == false then
  52.            colorsbp = 0
  53.      else
  54.            colorsbp = math.floor( printer.getBlackInkLevel() / 4000 * 100 )
  55.      end
  56.  
  57.      if printer.getPaperLevel() == false then
  58.            paperp = 0
  59.      else
  60.            paperp = math.floor( printer.getPaperLevel() / 256 * 100 )
  61.      end
  62.  
  63.      print("Цветная краска : "..colorscp.."%  Черная краска : "..colorsbp.."%")
  64.      print("Бумага : "..paperp.."%")
  65.  
  66.     io.write('printer >> ')
  67.     local string = io.read()
  68.     if string.sub(string, 1, 3) == "add" then
  69.           term.clear()
  70.           local text = {}
  71.       printer.writeln(string.sub(string, 5),color,"center")
  72.     end
  73.  
  74.     if string.sub(string, 1, 5) == "color" then
  75.           term.clear()
  76.           local curbackcolor = gpu.getBackground()
  77.           local curtextcolor = gpu.getForeground()
  78.           local I = 0
  79.           if gpu.getDepth() > 1 then
  80.           for k, v in pairs(colortable) do
  81.                 I = I + 1
  82.                 gpu.setBackground( v.hex )
  83.                 gpu.setForeground( 0xFFFFFF-v.hex )
  84.                 gpu.set(1,I,v.name)
  85.                 gpu.set(8,I,v.hexs)
  86.           end
  87.           gpu.setBackground(curbackcolor)
  88.           gpu.setForeground(curtextcolor)
  89.             else
  90.                   for k, v in pairs(colortable) do
  91.                         I = I + 1
  92.                         gpu.set(1,I,v.name)
  93.                         gpu.set(8,I,v.hexs)
  94.                   end
  95.             end
  96.             for _ = 1,#colortable/2 do
  97.                   print("\n")
  98.             end
  99.  
  100.           io.write('color >> ')
  101.           local string = io.read()
  102.           for k, v in pairs(colortable) do
  103.                 if v.name == string then
  104.                       color = v.hex
  105.                 end
  106.           end
  107.     end
  108.  
  109.     if string.sub(string, 1, 5) == "print" then
  110.           term.clear()
  111.           print("Идет распечатка...")
  112.         printer.print()
  113.         os.sleep(2)
  114.     end
  115.  
  116.     if string.sub(string, 1, 4) == "exit" then
  117.           term.clear()
  118.       print('Выход из программы произведен успешно. \n')
  119.       break
  120.     end
  121.  
  122.   end
  123. else
  124.       component.computer.beep(100,0.1)
  125.       component.computer.beep(100,0.1)
  126.       io.stderr:write('Принтер не найден. \n')
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement