Advertisement
Furry_02

Untitled

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