sidekick_

CC - Save Pixel Information

Apr 18th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local screenX, screenY = term.getSize()
  2. local current = { bg = colours.black, txt = colours.white }
  3. local screen = {}
  4.  
  5. for x = 1, screenX do
  6.     screen[x] = {}
  7.     for y = 1, screenY do
  8.         screen[x][y] = {
  9.             char = "",
  10.             bgcolor = colours.black,
  11.             txtcolor = colours.white
  12.         }
  13.     end
  14. end
  15.  
  16. -- Overwrite the globals
  17. function term.setTextColour( col )
  18.     current.txt = col
  19.     term.native.setTextColour( col )
  20. end
  21.  
  22. function term.setBackgroundColour( col )
  23.     current.bg = col
  24.     term.native.setBackgroundColour( col )
  25. end
  26.  
  27. function term.setTextColor( col )
  28.     current.txt = col
  29.     term.native.setTextColor( col )
  30. end
  31.  
  32. function term.setBackgroundColor( col )
  33.     current.bg = col
  34.     term.native.setBackgroundColor( col )
  35. end
  36.  
  37. function write( ... )
  38.     local x, y = term.getCursorPos()
  39.     local tmp = table.concat( {...}, " " )
  40.     for i = 1, tmp:len() do
  41.         screen[i + x - 1][y].char = tmp:sub( i, i )
  42.         screen[i + x - 1][y].bgcolor = current.bg
  43.         screen[i + x - 1][y].txtcolor = current.txt
  44.     end
  45.     term.native.write( tmp )
  46. end
  47.  
  48. function print( ... )
  49.     write( unpack( {...} ) )
  50.     term.setCursorPos( 1, ({term.getCursorPos()})[2] + 1 )
  51. end
  52.  
  53. local function getValueAt( key, x, y )
  54.     return screen[x][y][key]
  55. end
  56.  
  57. term.setBackgroundColour( colours.blue )
  58. term.clear()
  59.  
  60. term.setCursorPos( 3, 3 )
  61. term.setTextColor( colors.black )
  62. write( "hello" )
  63.  
  64. term.setCursorPos( 1, 1 )
  65. print( getValueAt( "char", 3, 3 ) .. " - " .. getValueAt( "txtcolor", 5, 3 ) .. " - " .. getValueAt( "bgcolor", 5, 3 ) )
Advertisement
Add Comment
Please, Sign In to add comment