Create graphics.lua
This commit is contained in:
parent
5a41cad6e4
commit
82d629d347
1 changed files with 37 additions and 0 deletions
37
src/apis/graphics.lua
Normal file
37
src/apis/graphics.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
function pixel(x, y, color)
|
||||
local ox, oy = term.getCursorPos()
|
||||
term.setCursorPos(x, y)
|
||||
term.setBackgroundColor(color)
|
||||
term.write(" ")
|
||||
term.setCursorPos(ox, oy)
|
||||
end
|
||||
|
||||
function line(x, y, x2, y2, color)
|
||||
local ox, oy = term.getCursorPos()
|
||||
if x == x2 then
|
||||
term.setBackgroundColor(color)
|
||||
for _y = y, y2 do
|
||||
term.setCursorPos(x, _y)
|
||||
term.write(" ")
|
||||
end
|
||||
elseif y == y2 then
|
||||
term.setBackgroundColor(color)
|
||||
for _x = x, x2 do
|
||||
term.setCursorPos(_x, y)
|
||||
term.write(" ")
|
||||
end
|
||||
else
|
||||
error("diagonal/other lines not supported")
|
||||
end
|
||||
term.setCursorPos(ox, oy)
|
||||
end
|
||||
|
||||
function box(x, y, x2, y2, color)
|
||||
local ox, oy = term.getCursorPos()
|
||||
term.setBackgroundColor(color)
|
||||
for _y = y, y2 do
|
||||
term.setCursorPos(x, _y)
|
||||
term.write(string.rep(" ", (x2 - x) + 1))
|
||||
end
|
||||
term.setCursorPos(ox, oy)
|
||||
end
|
Loading…
Reference in a new issue