Advertisement
Guest User

print.lua

a guest
Apr 8th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local printer = peripheral.find("printer")
  2.  
  3. local w, h = 25, 21
  4. local BARCODE_START = 128
  5. local BARCODE_CHARS = 32
  6.  
  7. local function generateBarcode()
  8.   local out = ""
  9.  
  10.   for y = 1, 4 do
  11.     for x = 1, w do
  12.       out = out .. string.char(math.random(BARCODE_START, BARCODE_START + BARCODE_CHARS))
  13.     end
  14.   end
  15.  
  16.   return out
  17. end
  18.  
  19. local function printBarcode(barcode)
  20.   local lines = math.ceil(#barcode / w)
  21.  
  22.   for y = 1, h + 2 do
  23.     --local line = barcode:sub(y * w, math.min((y + 1) * w, #barcode))
  24.     local line = ("A"):rep(w)
  25.     -- printer.setCursorPos(1, (h - lines) + y)
  26.     printer.setCursorPos(1, y)
  27.     printer.write(line)
  28.   end
  29. end
  30.  
  31. printer.newPage()
  32.  
  33. --local barcode = generateBarcode()
  34. --printBarcode(barcode)
  35.  
  36. for i = 1, 30 do
  37.   printer.setCursorPos(1, i)
  38.   printer.write(i)
  39. end
  40.  
  41. printer.endPage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement