This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SethShadowrider's profile picture

Fill A Screen More Efficiently?

Started by SethShadowrider, 23 July 2013 - 07:02 PM
SethShadowrider #1
Posted 23 July 2013 - 09:02 PM
So i'm working on a "Home integrated" OS (basically meaning it interacts with machines in my house and such using monitors and touchscreens) and i'm wondering if there's any very efficient ways to fill a screen. I want to draw a lot of different shapes on a monitor(or just a computer for now) and is there any way to quickly fill up a screen and draw buttons, etc? Im not looking for an API and ive tried various things like

local w, h = term.getSize()
term.setBackgroundcolor(colors.gray)
for h = 1,h do
   for w = 1, w do
      term.write(" ")
   end
end
And

term.setBackgroundcolor(colors.gray)
for h = 1,3 do
   for w = 1, 6 do
      term.write(" ")
   end
end
Any small overlooked snippets of code I could use? Because otherwise its going to add a lot of unnecessary length to the program doing that for every time I fill a screen or draw a box.
Kingdaro #2
Posted 23 July 2013 - 10:03 PM
term.clear() will use the current background color as the color to clear the screen with.


function fillScreen(color)
  term.setBackgroundColor(color)
  term.clear()
end
MysticT #3
Posted 23 July 2013 - 10:10 PM
For drawing boxes, you can use something like this:

local function drawBox(x, y, w, h, color)
  local line = string.rep(" ", w)
  term.setBackgroundColor(color)
  for i = 0, h-1 do
    term.setCursorPos(x, y + i)
    term.write(line)
  end
end
That way you draw a full line instead of only one character.