Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------
- --Init:
- -------
- --API-Test
- if ( qmain == nil ) then
- error("The QFormat API requires the QMain API! (Reboot to fix half-loaded APIs)", 0)
- end
- --Local Functions
- local getChar
- --Local Vars
- local default_image = {{"iiiiiiiiiiiiiiiiiiii","i i","i abcdefghijklmnop i","i dddddddddddddddd i","i i","iiiiiiiiiiiiiiiiiiii"},{"","",""," abcdefghijklmnop"},{"","",""," All Colors here!"}}
- ----------
- --Methods:
- ----------
- writeMarkup = function(...)
- --Input
- local input = {...}
- local default = {"&d&HDemo", {1, 1}, qmain.getScreen()}
- --Parameters
- local script = input[1] or default[1]
- local position = input[2] or default[2]
- local side = input[3] or default[3]
- --Peripheral
- local monitor = qmain.getMonitor(side)
- --Method
- monitor.setCursorPos(unpack(position))
- script = "a&D"..script.."&a&D&"
- for color, text in script:gmatch("(%a)(.-)&") do
- if (color:upper() == color) then
- monitor.setBackgroundColor(qmain.convertColor(color:lower()))
- else
- monitor.setTextColor(qmain.convertColor(color))
- end
- monitor.write(text)
- end
- end
- drawFilledBox = function(...)
- --Input
- local input = {...}
- local default = {"a", {1, 1}, {4, 3}, qmain.getScreen()}
- --Parameters
- local color = input[1] or default[1]
- local position = input[2] or default[2]
- local size = input[3] or default[3]
- local side = input[4] or default[4]
- --Peripheral
- local monitor = qmain.getMonitor(side)
- --Method
- monitor.setBackgroundColor(qmain.convertColor(color))
- for box_y = 1, size[2] do
- monitor.setCursorPos(position[1], position[2] + (box_y - 1))
- monitor.write(string.rep(" ", size[1]))
- end
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.black)
- end
- drawProgressBar = function(...)
- --Input
- local input = {...}
- local default = {0.4, {1, 1}, {10, 1}, {"i", "f"}, qmain.getScreen()}
- --Parameters
- local progress = input[1] or default[1]
- local position = input[2] or default[2]
- local size = input[3] or default[3]
- local colors = input[4] or default[4]
- local side = input[5] or default[5]
- --Peripheral
- local monitor = qmain.getMonitor(side)
- --Method
- local used_pixels = math.floor(progress * size[1])
- drawFilledBox(colors[2], position, size, side)
- drawFilledBox(colors[1], position, {used_pixels, size[2]}, side)
- end
- loadImage = function(...)
- --Input
- local input = {...}
- local default = {default_image}
- --Parameters
- local image = input[1] or default[1]
- --Method
- local data = {
- back = image[1] or {},
- col = image[2] or {},
- symbol = image[3] or {}
- }
- local max_x, max_y = 0, 0
- for name, value in pairs(data) do
- if (#value > max_y) then
- max_y = #value
- end
- for row, row_data in pairs(value) do
- if (row_data:len() > max_x) then
- max_x = row_data:len()
- end
- end
- end
- local new_image = {}
- for x = 1, max_x do
- new_image[x] = {}
- for y = 1, max_y do
- new_image[x][y] = {
- getChar(data.back, x, y),
- getChar(data.col, x, y),
- getChar(data.symbol, x, y)
- }
- end
- end
- return new_image
- end
- drawImage = function(...)
- --Input
- local input = {...}
- local default = {loadImage(default_image), {1, 1}, qmain.getScreen()}
- --Parameters
- local image = input[1] or default[1]
- local position = input[2] or default[2]
- local side = input[3] or default[3]
- --Peripheral
- local monitor = qmain.getMonitor(side)
- --Method
- for x = 1, #image do
- for y = 1, #image[1] do
- local backcolor = image[x][y][1]
- local textcolor = image[x][y][2]
- local symbol = image[x][y][3]
- if not(backcolor == " ") then
- monitor.setCursorPos(position[1] + x - 1, position[2] + y - 1)
- monitor.setBackgroundColor(qmain.convertColor(backcolor))
- if (textcolor == " ") then
- monitor.write(" ")
- else
- monitor.setTextColor(qmain.convertColor(textcolor))
- monitor.write(symbol)
- end
- end
- end
- end
- end
- ----------
- --Private:
- ----------
- getChar = function(array, x, y)
- if not(array == nil) then
- if not(array[y] == nil) then
- if not(array[y]:sub(x,x) == "") then
- return array[y]:sub(x,x)
- end
- end
- end
- return " "
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement