AliquotMesozoic

Example Button API

Jul 15th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. local nButtons = 3 --The number of buttons
  2. local nMaxButtonText = 10 --The fake maximum text length
  3.  
  4. term.setBackgroundColor(colors.black)
  5. term.clear()
  6.  
  7. local nPadding = 1
  8.  
  9. local termX, termY = term.getSize()
  10. local nMaxButtonLength = nMaxButtonText + (nPadding*2)
  11.  
  12. local nButtonDistance = (termX-(nMaxButtonLength*nButtons))/(nButtons-1)
  13. nButtonDistance = math.floor(nButtonDistance)
  14.  
  15. local function drawButton(x,y)
  16.     term.setCursorPos(x,y)
  17.     term.write(string.rep(" ",nMaxButtonText))
  18. end
  19.  
  20.  
  21. term.setBackgroundColor(colors.blue)
  22. local xCoord = 1
  23. for index=1,nButtons do
  24.     drawButton(xCoord, 5)
  25.     xCoord = xCoord + nMaxButtonLength + nButtonDistance
  26. end
Advertisement
Add Comment
Please, Sign In to add comment