Advertisement
Guest User

braille.lua

a guest
Jan 31st, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local gpu = component.gpu
  4.  
  5. local w, h = 40, 20
  6.  
  7. local ow, oh = gpu.getResolution()
  8. local brailleindex = {{0x1,0x8},{0x2,0x10},{0x4,0x20},{0x40,0x80}}
  9. local idfk = 0
  10. local btn = {[false] = 0, [true] = 1}
  11.  
  12. gpu.setResolution(w, h)
  13.  
  14. function generatePattern()
  15.   local outputstr = ""
  16.   s = math.sin(idfk)
  17.   c = math.cos(idfk)
  18.   for y=0, h-1 do
  19.     for x=0, w-1 do
  20.       local c = 0
  21.       for sy=0, 3 do
  22.         for sx=0, 1 do
  23.           local i = brailleindex[sy+1][sx+1]
  24.           local tx, ty = x * 2 + sx, y * 4 + sy
  25.           local nx, ny = tx + math.sin(idfk) * 50, ty + math.cos(idfk) * 50 -- math.floor(tx * c - ty * s), math.floor(tx * s + ty * c) -- failed attempt at rotozoom
  26.           local p = math.floor(math.sin(nx/4)+math.cos(ny/4)) % 2
  27.           c = c + p * i
  28.         end
  29.       end
  30.       outputstr = outputstr .. unicode.char(0x2800+c)
  31.     end
  32.   end
  33.   return outputstr
  34. end
  35.  
  36. while true do
  37.   io.write(generatePattern())
  38.   idfk = idfk + 0.025
  39.   if event.pull(0.01, "interrupted") == "interrupted" then
  40.     gpu.setResolution(ow, oh)
  41.     return
  42.   end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement