Advertisement
Mr_jack

Computercraft Center API

Jun 24th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. ---------------------------------------------------
  2. --Center-API-by-jack-------------------------------
  3. ---------------------------------------------------
  4. -- --How to use--
  5. -- Enter this function to include this API
  6. --
  7. -- os.loadAPI( enter here path to this API )
  8. --
  9. --
  10. -- --Functions--
  11. --
  12. -- Function: CentralWrite(y,text)
  13. --
  14. -- Description: Draws text on Center of Screen on
  15. -- different y
  16. --
  17. -- Example: CentralWrite(5,"hello") - writes hello
  18. -- on center of line #5
  19. --
  20. --
  21. -- Function: GetScrCenterX(pixels)
  22. --
  23. -- Description: Returns Center of Screen for
  24. -- Centered text or any needs (returns two poses
  25. -- start and end of center)
  26. --
  27. -- Example: GetScrCenterX(4) - returns two points
  28. -- of center to draw line or text with size
  29. -- 4 pixels
  30. --
  31. --
  32. -- Function: GetScrCenterY(pixels)
  33. --
  34. -- Description: Works as well as GetScrCenterX ,but
  35. -- gets two points of y center
  36. --
  37. -- Example: GetScrCenterY(3) - returns two points
  38. -- of center on Y axys for 3 pixels
  39. --
  40. --
  41. -- Function: GetCenter(start pos,end pos,pixels)
  42. --
  43. -- Description: Works as well as GetScrCenterX or
  44. -- GetScrCenterY ,but gets center two points with
  45. -- using entered start and end pos
  46. --
  47. -- Example: GetCenter(2,8,2) - gets two center
  48. -- points of entered here points of x axys
  49. --
  50. -- --The End--
  51. -- --Sorry for bad english--
  52. -- --Code of this api here--
  53. -- \/\/\/\/\/\/\/\/\/\/\/\/
  54. ---------------------------------------------------
  55.  
  56. function CentralWrite(y,text)
  57. scrX = term.getSize()
  58. x = (scrX/2)-(#text/2)
  59. term.setCursorPos(x,y)
  60. write(text)
  61. end
  62.  
  63. function GetScrCenterX(pixels)
  64. scrX = term.getSize()
  65. x = (scrX/2)-(pixels/2)
  66. x2 = x+pixels-1
  67. return x,x2
  68. end
  69.  
  70.  
  71. function GetScrCenterY(pixels)
  72. scrX,scrY = term.getSize()
  73. y = (scrY/2)-(pixels/2)
  74. y2 = y+pixels-1
  75. return y
  76. end
  77.  
  78. function GetCenter(SP,EP,pixels)
  79. Center = math.floor(SP+((EP-SP)/2)-pixels/2)
  80. CenterP2 = Center+pixels-1
  81. return Center,CenterP2
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement