Furry_02

Untitled

Jul 25th, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. (...)
  2.  
  3. local braillepixels = {"⠁", "⠂", "⠃", "⠄", "⠅", "⠆", "⠇", "⠈", "⠉", "⠊", "⠋", "⠌", "⠍", "⠎", "⠏", "⠐", "⠑", "⠒", "⠓", "⠔", "⠕", "⠖", "⠗", "⠘", "⠙", "⠚", "⠛", "⠜", "⠝", "⠞", "⠟", "⠠", "⠡", "⠢", "⠣", "⠤", "⠥", "⠦", "⠧", "⠨", "⠩", "⠪", "⠫", "⠬", "⠭", "⠮", "⠯", "⠰", "⠱", "⠲", "⠳", "⠴", "⠵", "⠶", "⠷", "⠸", "⠹", "⠺", "⠻", "⠼", "⠽", "⠾", "⠿", " "}
  4.  
  5.  
  6. local ocge = {}
  7.  
  8.  
  9. function round(n)
  10.   return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
  11. end
  12.  
  13. function normalize(coord) -- Internal function, do not touch!
  14.  
  15.   if (coord%1 == 0) then -- If 'coord' is already normalized, return 'coord'
  16.     return coord + 1
  17.   elseif (coord%1 ~= 0) then -- If 'coord' isn't normalized, round it and return the rounded value
  18.     return round(coord + 1)
  19.   end
  20. end
  21.  
  22. function get_pos(x, y) -- Internal function, do not touch!
  23.   -- Convert x, y, to cols, rows
  24.   return round(normalize(x) / 2), round(normalize(y) / 3 + 1)
  25. end
  26.  
  27. function setbraillepixel(x, y, chars, dots) -- Internal function, do not touch!
  28.  
  29.   local _chars = chars
  30.   _x = normalize(x)
  31.   _y = normalize(y)
  32.   col, row = get_pos(_x, _y)
  33.  
  34.   print("col: " .. tostring(col) .. "  " .. "row: " .. tostring(row) .. "  " .. serialization.serialize(_chars[row][col]))
  35.  
  36.   if (_chars[row][col] == nil) then
  37.     _chars[row][col] = 1
  38.   end
  39.   if (_chars[row][col]%1 ~= 0) then
  40.     return
  41.   end
  42.  
  43.   _chars[row][col] = bit32.bor(_chars[row][col], dots[ _y % 3 + 1][_x % 2 + 1])
  44.   return _chars
  45. end
  46.  
  47. function ocge.setbraillepixels(inputpixels, inputpixelcolors, x, y) -- Experimental drawing function, is not recommended for anything but non-transparent OCIMG files
  48.  
  49.   local dots = {{1, 8}, {2, 16}, {4, 32}}
  50.  
  51.   local chars = {}
  52.  
  53.   for i = 1, #inputpixels do
  54.     for k = 1, #inputpixels[i] do
  55.       table.insert(chars, {#braillepixels})
  56.     end
  57.   end
  58.  
  59.   for _y = 1, #inputpixels do
  60.     for _x = 1, #inputpixels[_y] do
  61.  
  62.       if (inputpixelcolors == nil) then
  63.       error("Pixel colors not defined")
  64.       end
  65.  
  66.  
  67.       if (inputpixels ~= nil) then
  68.       if (inputpixels[_y][_x] == 1) then
  69.       chars = setbraillepixel(_x, _y, chars, dots)
  70.       end
  71.       else
  72.       error("Pixels not defined")
  73.       end
  74.  
  75.     end
  76.   end
  77.  
  78.   for cy = 1, #chars do
  79.     for cx = 1, #chars[cy] do
  80.      
  81.       --gpu.setForeground(inputpixelcolors[cy][cx][1])
  82.       --gpu.setBackground(inputpixelcolors[cy][cx][2])
  83.       gpu.set(cx + x, cy + y, braillepixels[chars[cy][cx]])
  84.     end
  85.   end
  86.   print(serialization.serialize(chars))
  87. end
  88.  
  89. (...)
  90.  
  91. local pixels2 = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}
  92. local pixelcolors2 = {{{0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}}, {{0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}}}
  93.  
  94. term.setCursor(1, 0)
  95. ocge.setbraillepixels(pixels2, pixelcolors2, 25, 10)
Advertisement
Add Comment
Please, Sign In to add comment