Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Figlet font API
- -- Created by MaoZedong
- local function split(str)
- local parts = {}
- for part in str:gmatch("[^%s]+") do
- table.insert(parts, part)
- end
- return parts
- end
- local function skip(tbl, n)
- return table.pack(select(n + 1, table.unpack(tbl)))
- end
- local function esc(x)
- return (x:gsub('%%', '%%%%')
- :gsub('^%^', '%%^')
- :gsub('%$$', '%%$')
- :gsub('%(', '%%(')
- :gsub('%)', '%%)')
- :gsub('%.', '%%.')
- :gsub('%[', '%%[')
- :gsub('%]', '%%]')
- :gsub('%*', '%%*')
- :gsub('%+', '%%+')
- :gsub('%-', '%%-')
- :gsub('%?', '%%?'))
- end
- function parseFont(name)
- local f = fs.open(name, "r")
- local lines = {}
- for line in f.readLine do
- table.insert(lines, line)
- end
- f.close()
- local header = split(lines[1])
- local hardblank = header[1]:sub(#header[1], #header[1])
- local height = math.abs(tonumber(header[2]))
- local comments = math.abs(tonumber(header[6]))
- local fontLines = skip(lines, comments + 1)
- return {
- fontLines = fontLines,
- hardblank = hardblank,
- height = height,
- chars = {}
- }
- end
- local function parseChar(char, font)
- if font.chars[char] ~= nil then
- return font.chars[char]
- end
- local height = font.height
- local start = (string.byte(char) - 32) * height
- local charLines = {}
- for i = 1, height do
- charLines[i] = font.fontLines[start + i]
- :gsub("@", "")
- :gsub(esc(font.hardblank), " ")
- end
- font.chars[char] = charLines
- return charLines
- end
- function write(font, str)
- local chars = {}
- local result = ""
- for i = 1, #str do
- chars[i] = parseChar(str:sub(i, i), font)
- end
- for i = 1, #chars[1] do
- for j = 1, #str do
- result = result .. chars[j][i]
- end
- result = result .. "\n"
- end
- return result
- end
Advertisement
Add Comment
Please, Sign In to add comment