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

Help with paintutils.drawPixel()

Started by DaKillerBear1, 03 June 2015 - 08:10 AM
DaKillerBear1 #1
Posted 03 June 2015 - 10:10 AM
So i'm trying to use paintutils.drawPixel(), and everything goes fine untill I use term.clear(), which apparently fills the whole screen with the paintutils pixels. And I habve no ide why it does this, could someone help me??

A copy of my code:

function redraw() --The graphics part
  term.clear()
  paintutils.drawPixel(p1x, p1y, 2048)
  paintutils.drawPixel(p2x, p2y, 16384)
  term.setTextColor(colors.green)
  term.setCursorPos(1, 1)
  term.write(timeD)
end
Bomb Bloke #2
Posted 03 June 2015 - 10:32 AM
The source for paintutils.drawPixel() loosely goes like this:

function drawPixel(x, y, colour)
  term.setBackgroundColour(colour)
  term.setCursorPos(x, y)
  term.write(" ")
end

Whereas term.clear() goes like this:

function clear()
  local x, y = term.getSize()
  local curX, curY = term.getCursorPos()
  local line = string.rep(" ", x)  -- Generate a string as wide as the screen, filled with nothing but spaces.
  for i = 1, y do
    term.setCursorPos(1, i)
    term.write(line)
  end
  term.setCursorPos(curX, curY)
end

So drawPixel changes the background colour used when rendering text, and clear writes over the whole screen with the current background colour. See the fix? :)/>
DaKillerBear1 #3
Posted 03 June 2015 - 01:00 PM
Yup, change the background color before using term.clear() :)/>