Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local colors = require "colors"
- local component = require "component"
- local gpu = component.gpu
- local term = require 'term'
- local serialization = require "serialization"
- local unicode = require "unicode"
- local bit32 = require "bit32"
- local braillepixels = {" ", "⠁", "⠂", "⠃", "⠄", "⠅", "⠆", "⠇", "⠈", "⠉", "⠊", "⠋", "⠌", "⠍", "⠎", "⠏", "⠐", "⠑", "⠒", "⠓", "⠔", "⠕", "⠖", "⠗", "⠘", "⠙", "⠚", "⠛", "⠜", "⠝", "⠞", "⠟", "⠠", "⠡", "⠢", "⠣", "⠤", "⠥", "⠦", "⠧", "⠨", "⠩", "⠪", "⠫", "⠬", "⠭", "⠮", "⠯", "⠰", "⠱", "⠲", "⠳", "⠴", "⠵", "⠶", "⠷", "⠸", "⠹", "⠺", "⠻", "⠼", "⠽", "⠾", "⠿", " "}
- local ocge = {}
- function round(n)
- return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
- end
- function normalize(coord) -- Internal function, do not touch!
- if (coord%1 == 0) then -- If 'coord' is already normalized, return 'coord'
- return coord
- elseif (coord%1 ~= 0) then -- If 'coord' isn't normalized, round it and return the rounded value
- return round(coord)
- end
- end
- function get_pos(x, y) -- Internal function, do not touch!
- -- Convert x, y, to cols, rows
- return round(normalize(x) / 2), (round(normalize(y) / 3) + 1)
- end
- function DP(pixel) -- Internal function, do not touch!
- if (pixel == 0 or pixel == nil) then
- return " "
- else
- return pixel
- end
- end
- function setbraillepixel(x, y, chars, dots) -- Internal function, do not touch!
- local _chars = chars
- _x = normalize(x)
- _y = normalize(y)
- col, row = get_pos(_x, _y)
- --print("col: " .. tostring(col) .. " " .. "row: " .. tostring(row) .. " " .. "x: " .. tostring(_x) .. " " .. "y: " .. tostring(_y) .. " " .. serialization.serialize(_chars[row][col]))
- if (_chars[row][col] == nil) then
- _chars[row][col] = 1
- end
- if (_chars[row][col]%1 ~= 0) then
- return
- end
- _chars[row][col] = bit32.bor(_chars[row][col], dots[(_y % 3) + 1][(_x % 2) + 1])
- print("col: " .. tostring(col) .. " " .. "row: " .. tostring(row) .. " " .. "x: " .. tostring(_x) .. " " .. "y: " .. tostring(_y) .. " " .. serialization.serialize(_chars[row][col]))
- return _chars
- end
- function ocge.setbraillepixels(inputpixels, inputpixelcolors, x, y) -- Experimental drawing function, is not recommended for anything but non-transparent OCIMG files
- local dots = {
- {0x01, 0x08},
- {0x02, 0x10},
- {0x04, 0x20}
- }
- local chars = {}
- for i = 1, #inputpixels do
- for k = 1, #inputpixels[i] do
- table.insert(chars, {1})
- end
- end
- for _y = 1, #inputpixels do
- for _x = 1, #inputpixels[_y] do
- if (inputpixelcolors == nil) then
- error("Pixel colors not defined")
- end
- if (inputpixels ~= nil) then
- if (inputpixels[_y][_x] == 1) then
- chars = setbraillepixel(_x, _y, chars, dots)
- end
- else
- error("Pixels not defined")
- end
- end
- end
- for cy = 1, #chars do
- for cx = 1, #chars[cy] do
- --gpu.setForeground(inputpixelcolors[cy][cx][1])
- --gpu.setBackground(inputpixelcolors[cy][cx][2])
- gpu.set(cx + x, cy + y, braillepixels[chars[cy][cx]])
- end
- end
- print(serialization.serialize(chars))
- end
- local pixels2 = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}
- local pixelcolors2 = {{{0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}}, {{0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}, {0xFFFFFF, 0x000000}}}
- ocge.setbraillepixels(pixels2, pixelcolors2, 25, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement