Skip to content

Instantly share code, notes, and snippets.

@omgmog
Last active November 29, 2020 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omgmog/f929050b7ecd7f1fc7f072aef10487f8 to your computer and use it in GitHub Desktop.
Save omgmog/f929050b7ecd7f1fc7f072aef10487f8 to your computer and use it in GitHub Desktop.
custom 5x7 font for pico8, mostly based on this font: https://www.dafont.com/type-writer.font
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
global_y = 0
function mt(t1,t2)
local new = {}
for k,v in pairs(t1) do new[k] = v end
for k,v in pairs(t2) do new[k] = v end
return new
end
function ternary(cond ,t ,f )
if cond then return t else return f end
end
function write(str,opts)
opts = opts or {}
_opts = {
x=0,
y=global_y,
c=7
}
opts = mt(_opts,opts)
font = {
w=5,
h=7,
-- first num indicates starting value, 0 or 1
-- each number indicates number of 0 or 1 in a row
-- changes at each .
glyphs = {
{"0", "0.1.3.1.1.3.2.3.2.3.2.3.2.3.1.1.3"},
{"1", "0.2.1.3.2.2.1.1.1.4.1.4.1.4.1.2.5"},
{"2", "0.1.3.1.1.3.1.4.1.3.1.3.1.3.1.3.5"},
{"3", "0.1.3.1.1.3.1.4.1.2.2.5.2.3.1.1.3"},
{"4", "0.3.2.2.1.1.1.1.1.2.2.3.6.4.1.4.1"},
{"5", "1.6.4.1.5.3.5.2.3.1.1.3"},
{"6", "0.1.3.1.1.3.2.4.4.1.1.3.2.3.1.1.3"},
{"7", "1.5.4.1.4.1.3.1.3.1.3.1.3.1"},
{"8", "0.1.3.1.1.3.2.3.1.1.3.1.1.3.2.3.1.1.3"},
{"9", "0.1.3.1.1.3.2.3.1.1.4.4.2.3.1.1.3"},
{"a", "0.1.3.1.1.3.2.3.7.3.2.3.2.3.1"},
{"b", "1.4.1.1.3.2.3.5.1.1.3.2.3.5"},
{"c", "0.1.3.1.1.3.2.4.1.4.1.4.1.3.1.1.3.1"},
{"d", "1.4.1.1.3.2.3.2.3.2.3.2.3.5"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3.1"},
{"\"", "0.1.1.1.1.1.1.1.1"},
{":", "0.12.1.14.1"},
{";", "0.12.1.14.1.3.1"},
{"(", "0.3.1.3.1.3.1.4.1.4.1.5.1.5.1"},
{")", "0.1.1.5.1.5.1.4.1.4.1.3.1.3.1"},
{"[", "0.1.3.2.1.4.1.4.1.4.1.4.1.4.3"},
{"]", "0.1.3.4.1.4.1.4.1.4.1.4.1.2.3"},
{"{", "0.2.2.3.1.4.1.3.2.4.1.4.1.4.2"},
{"}", "0.1.2.4.1.4.1.4.2.3.1.4.1.3.2"},
{"<", "0.3.1.3.1.3.1.3.1.5.1.5.1.5.1"},
{">", "0.1.1.5.1.5.1.5.1.3.1.3.1.3.1"},
{"-", "0.16.3"},
{"+", "0.12.1.3.3.3.1"},
{"/", "0.4.1.3.1.4.1.3.1.3.1.4.1.3.1"},
{"\\", "1.1.5.1.4.1.5.1.5.1.4.1.5.1"},
}
}
_x = opts.x
_y = opts.y
letters = {}
for i=1,#str do
letter = sub(str,i,i)
add(letters,letter)
end
for k,v in pairs(letters) do
letter = nil
for _glyph in all(font.glyphs) do
if _glyph[1] == v then
letter = _glyph[2]
end
end
local _sx = _x
local _sy = _y
if letter != nil then
local _px = _sx
local _py = _sy
pixels = {}
local _p = sub(letter,1,1)
local prev = nil
for i=2,#letter do
cur = sub(letter,i,i)
if type(prev) == "number" and cur != "." then
cur = sub(letter, i-1, i)
end
if cur == "." then
_p = ternary(_p == "0", "1", "0")
else
for j=1,tonum(cur) do
add(pixels, _p)
end
end
prev = tonum(cur)
end
for i,p in pairs(pixels) do
i = i - 1
if i % font.w == 0 then
_py += 1
_sx = _x - (font.w * (i / font.w))
end
_px = _sx + i
if p == "0" then
pset(_px, _py, opts.c)
end
end
else
font.w = 8
print(v, _sx, _y + ((font.h - 2)/2), opts.c)
end
_x += font.w + 1
end
global_y += font.h + 2
end
function _draw()
cls()
global_y = 0 -- reset on each draw call
write("hello world")
write("this is max 🐱", {c=12})
write("my font brings all")
write("the devs to the yard")
write("0123456789")
write("abcdefghijklm")
write("nopqrstuvwxyz")
write(".,?!'\":;()[]{}-+/\\<>")
write("yes, this is a lot")
write("nicer to read! ♥")
write("")
write("█▒🐱⬇️░✽●♥☉웃⌂⬅️😐")
write("♪🅾️◆…➡️★⧗⬆️ˇ∧❎▤▥")
write("@#$%^&*")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment