Advertisement
Guest User

braille.lua

a guest
Jan 28th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.89 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local gpu = component.gpu
  4.  
  5. local w, h = gpu.getResolution()
  6. local brailleindex = {{0x1,0x8},{0x2,0x10},{0x4,0x20},{0x40,0x80}}
  7. local idfk = 0
  8. local btn = {[false] = 0, [true] = 1}
  9.  
  10. function generatePattern()
  11.   local outputstr = ""
  12.   for y=0, h-1 do
  13.     for x=0, w-1 do
  14.       local c = 0
  15.       for sy=0, 3 do
  16.         for sx=0, 1 do
  17.           local i = brailleindex[sy+1][sx+1]
  18.           local tx, ty = x * 2 + sx, y * 4 + sy
  19.           local p = (math.floor((tx * 0.25 + ty) / 8 + idfk) + btn[x > w * 0.25 and x < w * 0.75 and y > h * 0.25 and y < h * 0.75]) % 2
  20.           c = c + p * i
  21.         end
  22.       end
  23.       outputstr = outputstr .. unicode.char(0x2800+c)
  24.     end
  25.   end
  26.   return outputstr
  27. end
  28.  
  29. while true do
  30.   io.write(generatePattern())
  31.   idfk = idfk + 0.125
  32.   if event.pull(0.1, "interrupted") == "interrupted" then
  33.     return
  34.   end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement