From 82d629d3478772a97e7326104cdb1d361cc5a2a0 Mon Sep 17 00:00:00 2001 From: Ale2610 Date: Fri, 31 Jul 2015 20:29:29 +0200 Subject: [PATCH] Create graphics.lua --- src/apis/graphics.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/apis/graphics.lua diff --git a/src/apis/graphics.lua b/src/apis/graphics.lua new file mode 100644 index 0000000..31ab2e7 --- /dev/null +++ b/src/apis/graphics.lua @@ -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