local function mkblank(width, height) local t = {} for y = 1, height do local tt = {}; t[y] = tt for x = 1, width do tt[x] = false end end return t end local function output(t, width, height) io.write("P1\n" .. width .. " " .. height .. "\n") for _, tt in ipairs(t) do local nr = {} for j, v in ipairs(tt) do nr[j] = (v and "1" or "0") end nr[#nr + 1] = "\n" io.write(table.concat(nr)) end end local function linedraw_naiive(t, px, py, x, y) while px ~= x or py ~= y do if px < x then px = px + 1 end if px > x then px = px - 1 end if py < y then py = py + 1 end if py > y then py = py - 1 end t[py][px] = true end end -- https://en.wikipedia.org/wiki/Bresenham's_line_algorithm#All_cases the last one local function linedraw_bresenham_combined(t, px, py, x, y) local dx = math.abs(x - px) local sx = (px < x) and 1 or -1 local dy = -math.abs(y - py) local sy = (py < y) and 1 or -1 local error = dx + dy while true do t[py][px] = true local e2 = 2 * error if e2 >= dy then if px == x then break end error = error + dy px = px + sx end if e2 <= dx then if py == y then break end error = error + dx py = py + sy end end end -- local linedraw = linedraw_naiive local linedraw = linedraw_bresenham_combined local byte_R = string.byte("R") local function loadhershey(source) local glyphs = {} local i = 1 while i < #source do while source:sub(i, i) == "\n" do i = i + 1 end local id = assert(tonumber(source:sub(i, i + 4))) i = i + 5 local pointn = assert(tonumber(source:sub(i, i + 2))) i = i + 3 pointin, i = pointn - 1, i + 2 -- not sure what's up with this they're screwed local glyph = {} while glyphs[id] do id = id + 1 end -- maximum si glyphs[id] = glyph local part = {} glyph[1] = part for j = 1, pointn do local c1 = source:sub(i, i) if c1 == "\n" then i = i + 1 elseif c1 == " " then part = {} glyph[#glyph + 1] = part i = i + 2 else part[#part + 1] = { x = (c1:byte() - byte_R), y = (source:sub(i + 1, i + 1):byte() - byte_R), } i = i + 2 end end end return glyphs end local space = 19 local linespace = 25 local width, height = space * 72, 600 local grid = mkblank(width, height) --[=[ local glyphs = loadhershey([[ 1 9MWRMNV RRMVV RPSTS 2 16MWOMOV ROMSMUNUPSQ ROQSQURUUSVOV 3 11MXVNTMRMPNOPOSPURVTVVU 4 12MWOMOV ROMRMTNUPUSTURVOV 5 12MWOMOV ROMUM ROQSQ ROVUV 6 9MVOMOV ROMUM ROQSQ 7 15MXVNTMRMPNOPOSPURVTVVUVR RSRVR 8 9MWOMOV RUMUV ROQUQ 9 3PTRMRV 10 7NUSMSTRVPVOTOS 11 9MWOMOV RUMOS RQQUV 12 6MVOMOV ROVUV ]]) --]=] local glyphs do -- https://solhsa.com/hershey/fontprev.html -- please reboop files to remove the erroneous newlines in them thanks local file = assert(io.open("futural.jhf", "r")) glyphs = loadhershey(file:read("*a")) file:close() end -- linedraw(grid, 1,1, width,height/2) local function glyphdraw(grid, id, ox, oy, scale) scale = scale or 1 for _, part in ipairs(glyphs[id]) do if part[1] then local xx, yy = ox + part[1].x * scale, oy + part[1].y * scale for i = 2, #part do local x, y = ox + part[i].x * scale, oy + part[i].y * scale linedraw(grid, xx, yy, x, y) xx, yy = x, y end end end end local message = {} local message_s = "it's a meow MEOW =^^= world !! i hope you have a nice day. a wheeeeeeee meow why does that meow dissappear? I do not know. oh, i have to make it 72 cols wide i missed that so i am typing lots more text here entropyfilling aaaa don't guess me on this please sorry" local space_value_from_outer_space = (" "):byte() - 32 + 12345 for c in message_s:gmatch(".") do message[#message + 1] = c:byte() - 32 + 12345 end message[#message + 1] = space_value_from_outer_space local ox, oy = space, linespace local wormrowm = {} local wormwormlen = 0 local function drawtotalwormrowm() local lll = 0 for _, sworm in ipairs(wormrowm) do lll = lll + space * #sworm end local scabamgap = math.floor((width - lll - space) / (#wormrowm - 1)) io.stderr:write(tostring(scabamgap) .. "\n") -- it's sligtly fucked for _, sworm in ipairs(wormrowm) do for _, id2 in ipairs(sworm) do glyphdraw(grid, id2, ox, oy) ox = ox + space end ox = ox + scabamgap end wormrowm = {} wormwormlen = space ox, oy = space, oy + linespace end local worm = {} for _, id in ipairs(message) do if id ~= space_value_from_outer_space then worm[#worm + 1] = id else --nooonononono theree minutes to submisnitnoi --cant think -- -- it's brokeorenn!!! local wl = (#worm + 1) * space if wormwormlen + wl > width then drawtotalwormrowm() else wormrowm[#wormrowm + 1] = worm wormwormlen = wormwormlen + wl end worm = {} end end drawtotalwormrowm() --- iaaa it was the usuall silly last one not triggered issue this is really common in my programming output(grid, width, height)