Jump to content




Fill A Screen More Efficiently?

lua

  • You cannot reply to this topic
2 replies to this topic

#1 SethShadowrider

  • Members
  • 23 posts

Posted 23 July 2013 - 08: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.

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 23 July 2013 - 09: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


#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 23 July 2013 - 09: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users