xXm0dzXx

Personal API

Nov 21st, 2012
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. --- xXm0dzXx Default Programming API ---
  2. -- All my programs will have this :DD --
  3. ----------------------------------------
  4.  
  5. local x,y = term.getSize()
  6.  
  7. local function cPrint( txt ) --Version 2.0 of cPrint
  8. local function printC( text )
  9. x2,y2 = term.getCursorPos()
  10. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  11. write(text.. "\n")
  12. end
  13.  
  14. if type(txt) == "string" then
  15. printC( txt )
  16. elseif type(txt) == "table" then
  17. for i=1,#txt do
  18. printC( txt[i] )
  19. end
  20. end
  21. end
  22.  
  23. local drawingBoard = {
  24. ["A"] = colors.white,
  25. ["B"] = colors.orange,
  26. ["C"] = colors.magenta,
  27. ["D"] = colors.lightBlue,
  28. ["E"] = colors.yellow,
  29. ["F"] = colors.lime,
  30. ["G"] = colors.pink,
  31. ["H"] = colors.gray,
  32. ["I"] = colors.lightGray,
  33. ["J"] = colors.cyan,
  34. ["K"] = colors.purple,
  35. ["L"] = colors.blue,
  36. ["M"] = colors.brown,
  37. ["N"] = colors.green,
  38. ["O"] = colors.red,
  39. ["P"] = colors.black,
  40. }
  41.  
  42. local function advWrite( pos1, pos2, str )
  43. for i=1,#str do
  44. local symb = drawingBoard[ string.sub( str, i, i) ]
  45. term.setCursorPos( pos1 + (i-1) , pos2 )
  46. if symb then
  47. term.setBackgroundColour( symb )
  48. write(" ")
  49. end
  50. end
  51. end
  52.  
  53. local function setBG( col, colz )
  54. term.setBackgroundColour( col )
  55. term.clear()
  56. term.setCursorPos(1,1)
  57. term.setTextColour( colz )
  58. end
  59.  
  60. local function getLines( path )
  61. local tLines = {}
  62. local file = fs.open( path, "r" )
  63. if file then
  64. line = file.readLine()
  65. while line do
  66. tLines[ #tLines+1 ] = line
  67. line = file.readLine()
  68. end
  69. file.close()
  70. end
  71.  
  72. return tLines
  73. end
  74.  
  75. -- End of API --
Advertisement
Add Comment
Please, Sign In to add comment