add drawtext

master
Astoria 2 years ago
parent 6931440b59
commit cd1664f33b

@ -0,0 +1,35 @@
--Tom Thumb font https://robey.lag.net/2010/01/23/tiny-monospace-font.html
characters = {}
h = 3
v = 5
characters["a"] = {{false, true, false}, {true, false, true}, {true, true, true}, {true, false, true}, {true, false, true}}
characters["b"] = {{true, true, false}, {true, false, true}, {true, true, false}, {true, false, true}, {true, true, false}}
characters["c"] = {{false, true, true}, {true, false, false}, {true, false, false}, {true, false, false}, {false, true, true}}
characters["d"] = {{true, true, false}, {true, false, true}, {true, false, true}, {true, false, true}, {true, true, false}}
characters["e"] = {{true, true, true}, {true, false, false}, {true, true, true}, {true, false, false}, {true, true, true}}
characters["f"] = {{true, true, true}, {true, false, false}, {true, true, true}, {true, false, false}, {true, false, false}}
characters["g"] = {{false, true, true}, {true, false, false}, {true, true, true}, {true, false, true}, {false, true, true}}
characters["h"] = {{true, false, true}, {true, false, true}, {true, true, true}, {true, false, true}, {true, false, true}}
characters["i"] = {{true, true, true}, {false, true, false}, {false, true, false}, {false, true, false}, {true, true, true}}
characters["j"] = {{false, false, true}, {false, false, true}, {false, false, true}, {true, false, true}, {false, true, false}}
characters["k"] = {{true, false, true}, {true, false, true}, {true, true, false}, {true, false, true}, {true, false, true}}
characters["l"] = {{true, false, false}, {true, false, false}, {true, false, false}, {true, false, false}, {true, true, true}}
characters["m"] = {{true, false, true}, {true, true, true}, {true, true, true}, {true, false, true}, {true, false, true}}
characters["n"] = {{true, false, true}, {true, true, true}, {true, true, true}, {true, true, true}, {true, false, true}}
characters["o"] = {{false, true, false}, {true, false, true}, {true, false, true}, {true, false, true}, {false, true, false}}
characters["p"] = {{true, true, false}, {true, false, true}, {true, true, false}, {true, false, false}, {true, false, false}}
characters["q"] = {{false, true, false}, {true, false, true}, {true, false, true}, {true, true, true}, {false, true, true}}
characters["r"] = {{true, true, false}, {true, false, true}, {true, true, true}, {true, true, false}, {true, false, true}}
characters["s"] = {{false, true, true}, {true, false, false}, {false, true, false}, {false, false, true}, {true, true, false}}
characters["t"] = {{true, true, true}, {false, true, false}, {false, true, false}, {false, true, false}, {false, true, false}}
characters["u"] = {{true, false, true}, {true, false, true}, {true, false, true}, {true, false, true}, {false, true, true}}
characters["v"] = {{true, false, true}, {true, false, true}, {true, false, true}, {true, false, true}, {false, true, false}}
characters["w"] = {{true, false, true}, {true, false, true}, {true, true, true}, {true, true, true}, {true, false, true}}
characters["x"] = {{true, false, true}, {true, false, true}, {false, true, false}, {true, false, true}, {true, false, true}}
characters["y"] = {{true, false, true}, {true, false, true}, {false, true, false}, {false, true, false}, {false, true, false}}
characters["z"] = {{true, true, true}, {false, false, true}, {false, true, false}, {true, false, false}, {true, true, true}}
characters[" "] = {{}, {}, {}, {}, {}}
characters["."] = {{}, {}, {}, {}, {false, true, false}}
characters["!"] = {{false, true, false}, {false, true, false}, {false, true, false}, {}, {false, true, false}}
characters["?"] = {{true, true, true}, {false, false, true}, {false, true, false}, {}, {false, true, false}}
characters["NOSYMBOL"] = {{false, false, false}, {true, true, false}, {true, false, true}, {true,true,true}, {true, false, true}}

@ -0,0 +1,40 @@
--Get Font
dofile("draw/characters")
--For each letter draw a character.
function drawText(gpu, cstring, x, y, red, green, blue, alpha)
for pos=1,string.len(cstring),1 do
drawChar(gpu, string.sub(string.lower(cstring), pos, pos), x + ((pos - 1) * 4), y, red, green, blue, alpha)
end
end
--Draw a single character.
function drawChar(gpu, character, x, y, red, green, blue, alpha)
gpured, gpublue, gpugreen, gpualpha = gpu.getColor()
red = red or gpured
blue = blue or gpublue
green = green or gpugreen
alpha = alpha or gpualpha
if (type(alpha) == "nil") then
alpha = 255
end
gpu.setColor(red, green, blue, alpha)
for ix=1,h,1 do
for iy=1,v,1 do
if (type(characters[character]) == "table") then
if(characters[character][iy][ix] == true) then
gpu.plot(ix+x,iy+y)
end
else
if(characters["?"][iy][ix] == true) then
gpu.setColor(255, 0, 0, 255)
gpu.plot(ix+x,iy+y)
else
gpu.setColor(0, 0, 0, 255)
gpu.plot(ix+x,iy+y)
end
gpu.setColor(red, green, blue, alpha)
end
end
end
end

@ -0,0 +1,6 @@
os.loadAPI("drawtext")
gpu = peripheral.wrap("right")
gpu.setColor(0,0,0)
gpu.fill()
gpu.setColor(255,255,255)
drawtext.drawText(gpu, "test#", 1, 3)
Loading…
Cancel
Save